Re: When to check the return value of malloc



On Fri, 18 Jan 2008 22:39:24 -0500, CBFalconer <cbfalconer@xxxxxxxxx>
wrote:

Randy Howard wrote:
Eric Sosman wrote

"Obviously," you can allocate an infinite amount of
memory as long as you get it in 20-byte chunks? Did you
used to work for Enron or something?

This thread was useful, now I know I never have to buy extra
memory again.

PROVIDED you malloc it in 20 byte chunks. Since the standard
specifies that freed memory be made available again, you must be
perfectly safe in allocating 4k by:

for (i = 0; i < 20; i++) a[i] = malloc(20);
for (i = 0; i < 20; i++) free(a[i]);
ptr = malloc(4000);

with suitable declarations for a, i, ptr, and all the needed
#includes. Learning is wunnerful.

Apparently this is some strange new value of 20 * 20 of which I was
previously unaware.

(I know it's a joke, but cf. Twain on lightning != lightningbug.)
<G>
- formerly david.thompson1 || achar(64) || worldnet.att.net
.



Relevant Pages

  • Re: random writing access to a file in Python
    ... the size of available memory for the sorting operation (making it ... possible to work on larger chunks of data in memory) has less impact ... In the second run the size of processed chunks between reading/writing was in the order of up to tenths of Megabytes, where in the first run in order of up to hundreds Megabytes. ... decision about the size of buffers for merge sorting the chunks into the final file, so that they all fit into the 300 MByte of used memory ...
    (comp.lang.python)
  • Re: open a very big file
    ... Suppose the file had 50 rows and you had to find the sum of the numbers. ... to load data in chunks which fit in the memory ". ... If you still run into memory issues with the above, ...
    (comp.soft-sys.matlab)
  • Re: Efficient algorithm for finding duplicates in 56-bit number
    ... |) processor time) it would take to sort millions of those values ... and that'a a heck of a big IF (if it fits in memory). ... | chunk fits in memory) and then merges the chunks. ...
    (comp.programming)
  • block move clarification - System.Move()
    ... time, with chunks capable of being expressed in 8 bit, 16 bit and 32 bit ... I've been working on pooling memory and working out ways to make the memory ... each buffer already in existence. ... But I do not know ASM, which is why I am here. ...
    (borland.public.delphi.language.basm)
  • Re: python memory blow out
    ... >> allocates memory in 256 kB chunks and never releases it. ... Large chunks are returned to the platform C when they become ... > to release memory back to the operating system once the 256kb chunk is ... the patch may return such a 256KB chunk to the platform C ...
    (comp.lang.python)