Re: How much memory



Nigel wrote:

Is it, for some reason, a bad idea to allocate upwards of 1 megabyte
on the heap via malloc? The reason I ask is that it seems fine, but I
haven't seen people do it before. Perhaps malloc, free and realloc are
inefficient for this much memory?

I routinely do this, sometimes with allocations up to a GiB or more. If
you're working with DOS it would be different, because of the restrictions
imposed there when using a legacy mode.

Consider that if you have an offscreen matrix of pixels for an image that
fills the screen you would need this much memory with a 1280x1024 display:
% set size [expr {1280 * 1024 * 4}]
5242880

Now let's see how much that is in terms of MiB:
% expr {$size / 1024.0 / 1024.0}
5.0

That's 5 megabytes or if you're a disk manufacturer 5 mebibytes. Some
systems might optimize that to be stored in VRAM (video RAM). Windows for
instance creates VRAM-backed bitmaps from what I understand in some cases
with certain Win32 calls.

-George
.



Relevant Pages

  • malloc realloc and pointers
    ... When we perform malloc(), the memory allocated dynamically comes from ... the heap area of the process in concern. ... perticular position in a buffer then on performing a ...
    (comp.lang.c)
  • Re: stack and heap
    ... books explain that local stack variables for each function are automatically allocated when function starts and deallocated when it exits. ... malloc() always takes memory in the heap. ...
    (comp.programming)
  • malloc and realloc
    ... When we perform malloc(), the memory allocated dynamically comes ... from the heap area of the process in concern. ... perticular position in a buffer then on performing a ...
    (comp.lang.c)
  • Re: Understanding Linux addr space, malloc, and heap
    ... > I don't understand what is happening with malloc and the heap in my ... > chunk of memory that holds dynamically-allocated memory. ... the "heap" is still brk in linux, however there is no 1:1 relation ... between heap and malloc. ...
    (Linux-Kernel)
  • Thank You -- Thomas J. Gritzan
    ... Thomas -- Your suggestion to malloc() out a block of memory was the ... Below are some details of my memory issues ... ... As a work around solution I guessed a ram disk would solve the ... persistence will frustrate the off topic police and give them a target ...
    (comp.lang.c)