[physfs] Replace malloc/strcpy by strdup
darkuranium at gmail.com
Wed Sep 29 12:07:50 EDT 2010
>Perhaps, it might be an idea to get rid of dynamically allocated
>path strings, and use arrays instead ? This might vastly improve
>performance at cost of memory, I suspect.
You mean using "char foo" as opposed to "char* foo = malloc(5)"? I'm not
sure what you mean because dynamically allocated path strings are pretty
much arrays (all strings are).
If you do mean using foo, then there's no change, only that it allocates
things on the stack, which is much more limited and can have horrible
consequences if an overflow happens. Furthermore, the size is fixed, meaning
that you can't, in this extreme case, use the path "hello" because it uses 6
characters ("hello" + \0 termination).
On 29 September 2010 17:58, Tolga Dalman <tolga.dalman at googlemail.com>wrote:
> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
> On 09/29/10 17:33, Christoph Nelles wrote:
> > yes, looks like this is a problem:
> > http://stackoverflow.com/questions/482375/strdup-function
> Indeed, strdup is POSIX only.
> > And you are forced to use free(). allocator.malloc/free may use other
> > functions.
> > So why worrying about saving one LOC.
> Actually, I sent the patch for fixing the erroneous check.
> Perhaps, it might be an idea to get rid of dynamically allocated
> path strings, and use arrays instead ? This might vastly improve
> performance at cost of memory, I suspect.
> Are there any PhysFS performance tests available ?
> -----BEGIN PGP SIGNATURE-----
> Version: GnuPG v2.0.16 (GNU/Linux)
> Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/
> -----END PGP SIGNATURE-----
> physfs mailing list
> physfs at icculus.org
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the physfs