Is it safe to call UseZipPacker more than once?

Just starting out? Need help? Post your questions and find answers here.
Karig
New User
New User
Posts: 7
Joined: Mon Jul 11, 2016 10:20 pm

Is it safe to call UseZipPacker more than once?

Post by Karig »

I'm thinking of writing a PureBasic module for reading DOCX files. Since a DOCX file is really a ZIP file, I'd call UseZipPacker() before reading the file.

My question is: If I want to write another module in the same program that also accesses some kind of ZIP file, is it safe for that other module to call UseZipPacker() a second time, or will that waste resources?
User avatar
Shield
Addict
Addict
Posts: 1021
Joined: Fri Jan 21, 2011 8:25 am
Location: 'stralia!
Contact:

Re: Is it safe to call UseZipPacker more than once?

Post by Shield »

Yeah, to my knowledge it is completely save to do that as these UseXXX() functions are mainly used to
trigger linking with all the library functions.
Image
Blog: Why Does It Suck? (http://whydoesitsuck.com/)
"You can disagree with me as much as you want, but during this talk, by definition, anybody who disagrees is stupid and ugly."
- Linus Torvalds
User avatar
Lunasole
Addict
Addict
Posts: 1091
Joined: Mon Oct 26, 2015 2:55 am
Location: UA
Contact:

Re: Is it safe to call UseZipPacker more than once?

Post by Lunasole »

Yes, it is safe. And be sure that this is one of the very minor questions you should care about when writing something more or less complex in PB ^^

Btw, if you deal successfully with DOCX, maybe you have some ideas about XLS/XSLX? I didn't find any way to read/save them, except one depending on MS components.
"W̷i̷s̷h̷i̷n̷g o̷n a s̷t̷a̷r"
User avatar
Keya
Addict
Addict
Posts: 1890
Joined: Thu Jun 04, 2015 7:10 am

Re: Is it safe to call UseZipPacker more than once?

Post by Keya »

Another way to check confirmation is just check the resulting executables with both one vs two instances of the UseXxxCodec() as they should be the same size if it's ok to use twice, which is indeed the case with UseZip. I think internally such functions use runtime defined constants (IF DEF...) to prevent multiple inclusion, although interestingly there's a small section of about 40 or so bytes that change!
Post Reply