[physfs] Replace malloc/strcpy by strdup

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


-----BEGIN PGP SIGNED MESSAGE-----
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.

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

iQEcBAEBAgAGBQJMpDaEAAoJEI0vwg8AaIlURs8IALhj/0dznXaJHIF5BegrDpeO
JgDNhMSY7UMWX+k8mkNNYcdN3UJ8kHMrtxBGJmaC+bv/482P+lOSLC4Vl4QRQrQw
Mg8rM+rPOcm2R99gP0N2ObuqlAeaefv5xJ3O79JbHbNbggTUBUFhHApogK4Afeh/
hhHXsFDN//9pcNkvuGW8ZCWQVFA3E/MXPN6mHSJSoB9XJqz2q6z1P5jp/jOkeGxJ
NYhxroLKAcAtVusJ3zT1eI4/uW9oFmHJ8CAxE5N8DEUxygBaP3QTnp99ejsaDbXM
+XLOIHITegRXRkwK3RrVfystrpsADDPGIdHO6+4zlhXH4GGqp36Vjmgk5lWxzLk=
=Rfgx
-----END PGP SIGNATURE-----
-------------- 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