From: Eric M. <er...@aj...> - 2000-08-31 00:36:18
|
On Wed, 30 Aug 2000, Jim Ingham wrote: > > Most virtual memory systems give an address space to the application > which is governed, not by the available memory on the machine, but by > the size of the address space. Actually, the available space is usually > less than the absolute max, since the stack is up at the top, and most > systems don't start it at the tip-top of the address space. For > instance MacOS X on a 32 bit processor loads the stack starting around > 0xc000000 for some reason. Still this is two Gig less the code space > and stack space for the app for a 32 bit machine. So the > "totalMemorySize" in your above equation is at least 2Gig or so big on a > 32 bit machine. I don't think we need to worry too much about that; a > Tcl programmer who reads more than a Gig into a single string is > probably doing something wrong anyway, and if they really need to do > that they should go out and buy themselves a 64 bit machine... And we > probably won't be running Tcl on any more 16 bit processors in the near > future, most of the hand-held devices like Palm, etc use 32 bit > processors. This may be true on MacOS X, but a little experiment on my Linux box shows that the memory allocation functions more the way that I expect than the way that you expect. This is a 32-bit machine, so yes, I can address 2 GB of memory. However, I have 192MB of physical memory plus 256 MB of swap space; when I try to allocate more than this amount of memory, malloc fails. It doesn't matter that I can address 2 GB of memory; my system just doesn't have the memory to give me. With the original code, if I had a 230MB string (unusual, perhaps, but not completely unrealistic), I would be unable to append even a single byte to it, simply because Tcl would try to allocate 460 MB, and on my system, that would fail. With the new code, I can happily append all the way up to the entirety of my available memory. The code I used to test my hypothesis: #include <stdio.h> int main() { char *c; c = (char *)malloc(/* 460 Megabytes */ 482344960); printf("return from malloc: %X\n", c); return 0; } Compiled and executed like so: gcc -o foo foo.c ./foo produces this result: return from malloc: 0 Eric Melski The Other Tcl Guy ericm at ajubasolutions.com Ajuba Solutions -- The TclCore mailing list is sponsored by Ajuba Solutions To unsubscribe: email tcl...@aj... with the word UNSUBSCRIBE as the subject. |