Initializing structure arrays



Is there an effective way to allocate memory and initialize a
structure array? For example, let's say we have a 1x1000000 myArray
structure array with fields
..name
..age
where .name is a string of unknown length, but length probably not to
exceed 30, and .age is an integer, say a uint8

we have tried the technique of repmat, i.e.

myArray.name='John Chrysanthemum Doe';
myArray.age=18;

myArray=repmat(myArray,1,1000000);

however, due to matlab's delayed copy, it does not actually allocate
memory for this. I know this for a fact because I was dealing with
1 gig variables and I could repmat them with impunity.

if instead we start with
myArray(1,1000000).name='John Chrysanthemum Doe';
myArray(1,1000000).age=18;

then certainly some memory will be allocated to the other ~million
entries, but they are set to be empty matrices. is the right amount
of space (~30 characters) reserved for the .name field?

is there any other technique? commands like ones( ),
zeros( ) only take elementary classnames?

Gregory Jones
.



Relevant Pages

  • Tru64 issues with Infinite limits
    ... An automated test in my nightly build was failing due to Out of Memory ... Cannot allocate block 146 ...
    (comp.unix.tru64)
  • Re: run-time vs compile-time
    ... > offset related to some location (like stack base) somewhere. ... > offset from heap to pi. ... When you allocate an int on the heap, it is allocated at address 1. ... application has a given amount of memory it can use as it wishes. ...
    (alt.comp.lang.learn.c-cpp)
  • Re: run-time vs compile-time
    ... > offset related to some location (like stack base) somewhere. ... > offset from heap to pi. ... When you allocate an int on the heap, it is allocated at address 1. ... application has a given amount of memory it can use as it wishes. ...
    (comp.lang.cpp)
  • Re: Sharing memory between kernelspace and userspace
    ... deallocate, on a totally dynamic basis, userspace ... Let userspace allocate shared memory visible to multiple ... and pass that into the kernel for it to write to. ...
    (Linux-Kernel)
  • Re: [ckrm-tech] RFC: Memory Controller
    ... I'd pay more attention to kernel memory accounting and less ... How would you allocate memory on NUMA in advance? ...
    (Linux-Kernel)

Loading