[physfs] Replace malloc/strcpy by strdup

Tolga Dalman tolga.dalman at googlemail.com
Thu Sep 30 03:04:36 EDT 2010

Hash: SHA1

On 09/29/10 18:59, Christoph Nelles wrote:
> Am 29.09.2010 17:58, schrieb Tolga Dalman:
>> 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.
> That is a good idea, but to support old C standards resp. compilers you
> have to declare them at the beginning of the blocks, probably wasting
> memory if unneeded. A problem might be maximum length of paths. Systems
> have a maximum path length MAX_PATH (or PATH_MAX?) and this might be
> exceeded by virtual paths with utf-8 characters in it. So you would have
> to limit it or stick with dynamically allocated memory.

You are talking about variable length arrays ? I.e:
  struct S {
    /* other variables */
    char buf[];
This is also possible of course, but also prone to programming
errors to my experience. I was rather talking about stack arrays of
fixed size.

Most operating systems have a limit on the maximum path length anyway
AFAIK. PATH_MAX is at least 255 according to POSIX and 1023 according
to SUSv2. On modern Linux this limit is at 4096 bytes, but I don't know
about other OSes.

Using stack arrays instead of heap-allocated memory is often worth the
memory waste due to better alignment, no indirect calls, less memory
fragmentation etc.
However, without a proper PhysFS benchmark, we can just speculate about
any numbers.

Having said this, I attached the patch, as it was originally intended:
an erroneous check is fixed.

Tolga Dalman
Version: GnuPG v2.0.16 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: physfs.c.diff
URL: <http://icculus.org/pipermail/physfs/attachments/20100930/00498737/attachment.diff>

More information about the physfs mailing list