Re: heap allocation of arrays



Richard E Maine wrote:

glen herrmannsfeldt <gah@xxxxxxxxxxxxxxxx> wrote:

Why not just us ALLOCATABLE arrays?
(snip)

Because sometimes automatics are more convenient. And because I find it
bizzare to choose coding style based on such a criterion. The standard
doesn't hint that this should be a difference between allocatable and
automatic.

(big snip)

Well, to me it depends on where the problem occurs.

As I understand it, C only claims to allow arrays up to 32767.
That is, the standard makes no guarantee past that.

If someone wants to allocate a 100GB array with current technology,
then likely they will have to do something special. The standard may
not say it, but it should be obvious, anyway.

On the other hand, some systems may require the stack size to be
specified at link time. I still remember a Microsoft LINK that
I ran on OS/2 with virtual memory and even larger virtual stack,
but set a default of 2K bytes for stack.

On another hand, many systems are designed around C's allocation,
assuming the use of malloc() for large arrays. (That is, assuming C.)
Since C89 allows only constant length (bounds) for automatic arrays,
it is rare to use them for large arrays. For such systems, malloc()
allocation for automatic arrays would seem an obvious solution.

Still, I believe that for reasonable systems heap allocation should
only be needed for really large arrays. There are still many
unreasonable systems around, though.

You did snip my suggestion for size dependence. Stack allocation
should be more efficient, and cause less fragmentation (of virtual
memory) for smaller arrays.

-- glen

.



Relevant Pages

  • Re: Statement on Schildt submitted to wikipedia today
    ... However, what Schildt described was not an abstract stack, but a specific ... to think about automatic variable allocation is...", ... support the contention that the standard was designed "to protect profits". ...
    (comp.lang.c.moderated)
  • Re: Looking for free memory pool software
    ... that the standard doesn't use the word "stack" doesn't mean that it ... This "stack" could easily be implemented as, say, a linked ... specified anything about the order of allocation and deallocation of ... Allocation occurs at some ...
    (comp.lang.c)
  • dgemm subroutine in BLAS - I think Ive cracked the difference, please confirm
    ... see what I'm talking about), so in the current state of memory allocation, ... but I have a problem when it comes to applying the dimensions. ... > In the Fortran 66 days it was because dynamic allocation didn't exist, ... > you allocate arrays big enough for the largest problem you might run into. ...
    (comp.lang.fortran)
  • Re: Fortran memory allocation (stack/heap) issues
    ... > rather than Fortran, ... dynamic allocation, and relatively little stack allocation. ... value return and arrays by reference. ...
    (comp.lang.fortran)
  • Re: Save attribute for 3d arrays
    ... not deallocate and reallocate the arrays or anything like that. ... of logic that would connect the segfault to SAVE somehow not working. ... Odds are that there is an unrelated error somewhere else that is causing ... allocation. ...
    (comp.lang.fortran)