The International Simutrans Forum

Development => Patches & Projects => Incorporated Patches and Solved Bug Reports => Topic started by: knightly on June 07, 2009, 10:58:44 am

Title: [Bug r2506] freelist_t does not support 64-bit compilations
Post by: knightly on June 07, 2009, 10:58:44 am
A bug has been reported by Pugget here (http://forum.simutrans.com/index.php?topic=2405.msg24070#msg24070), and I have found the cause of it (please see my explanation lower in that thread).

Although for the time being Simutrans Standards doesn't seem to request 4-bytes memory pieces from freelist_t, it is still safer to fix it and make freelist_t 64-bit compliant.

Thank you very much for your attention.
Title: Re: [Bug r2506] freelist_t does not support 64-bit compilations
Post by: prissi on June 11, 2009, 08:28:07 am
As new is called quite often, and for million of objects, another check as well a granularity of 8 is not desired. Maybe rather init the first enry with (const void *)-1, this should give a memory error when accessing it.
Title: Re: [Bug r2506] freelist_t does not support 64-bit compilations
Post by: jamespetts on June 11, 2009, 10:43:24 pm
If it just generates a memory error, doesn't that just change the nature of the problem rather than solving it?
Title: Re: [Bug r2506] freelist_t does not support 64-bit compilations
Post by: prissi on June 12, 2009, 01:12:43 pm
I just put 4 Byte entries to 8 Byte for the time being in freelist; it should work for experimental too.
Title: Re: [Bug r2506] freelist_t does not support 64-bit compilations
Post by: jamespetts on June 12, 2009, 02:27:27 pm
Thank you very much :-)
Title: Re: [Bug r2506] freelist_t does not support 64-bit compilations
Post by: knightly on June 12, 2009, 03:53:51 pm
@ Prissi

I don't know if this will work or not, but how about adding a static const variable to freelist_t :

Quote
   static const uint8 min_size = (uint8) ( sizeof(freelist_t*) >> 2 );

and then use this in

Quote
   size = max( min_size, size );

I guess when someone tries to compile a 64-bit version, sizeof(freelist_t*) will return 8 during compile time. In this way, 32-bit version can still use 4-byte memory pieces.
Title: Re: [Bug r2506] freelist_t does not support 64-bit compilations
Post by: prissi on June 12, 2009, 08:03:55 pm
I am neutral on this, as it will be very unlikely that I will use 4 byte pieces via new (since this will impact chaching quite bad ... ) So this can be used too.
Title: Re: [Bug r2506] freelist_t does not support 64-bit compilations
Post by: jamespetts on June 12, 2009, 09:57:09 pm
In either event, all of this should be behind an #ifdef for 64-but, shouldn't it?
Title: Re: [Bug r2506] freelist_t does not support 64-bit compilations
Post by: prissi on June 12, 2009, 10:21:32 pm
No; proper C code should do without that. The part that would need a different structure are the data of treeobj and grund_t and palnquadrat_t, as they consume much memory and an misalignment is wasted memory. Unfourtunately this is very much architecture and compilerdependent. It is currently optimized for GCC 3.x 32bit on windows; any other compiler wastes usually some space.

Furthermore in the foreseeable future there will be no official 64bit release, due to the disadvantages of using 64bit. (Of course only for plattforms that does not require 64bit. But most of them are only workstations or higher ... )
Title: Re: [Bug r2506] freelist_t does not support 64-bit compilations
Post by: jamespetts on June 12, 2009, 10:28:10 pm
Prissi,

when I tried to use it with Simutrans-Experimental, I got a freelist error when I loaded Pak128...
Title: Re: [Bug r2506] freelist_t does not support 64-bit compilations
Post by: knightly on June 13, 2009, 07:30:27 am
Thanks for considering my suggestion, Prissi. :)

I am neutral on this, as it will be very unlikely that I will use 4 byte pieces via new (since this will impact chaching quite bad ... ) So this can be used too.

May I know why using 4-byte memory pieces will impact caching badly?
Title: Re: [Bug r2506] freelist_t does not support 64-bit compilations
Post by: jamespetts on June 13, 2009, 10:56:09 am
Prissi,

aha, thank you - the latest change now makes it work. Very helpful!
Title: Re: [Bug r2506] freelist_t does not support 64-bit compilations
Post by: prissi on June 13, 2009, 09:43:08 pm
@Knightly
Any quantity that is scattered in four byte block around the memory is bad, since most processors need to read 16Byte block at least to get a single bit. Thus arrays are much much needed for performance, if there is not a *very* good reason to do otherwise. The objects on the map are not acessed too often, and moreover some of them are even multiples of 16Bytes. Moreover, as there are millions of them, no other option is left.

BTW: Standard malloc will at least return a 16Byte chunk ...
Title: Re: [Bug r2506] freelist_t does not support 64-bit compilations
Post by: knightly on June 14, 2009, 06:34:22 am

I see. Thanks a lot for your explanation, Prissi :)