S
Steve555
Hi
I've been working with C++ and Objective-C and I've forgotten how to
allocate memory for an array of structs in C.
Given a struct:
typedef struct {
double a,b,c,d;
long e,f,g,h;
} MyStruct
I want to do the equivalent of :
MyStruct **myStructArray;
myStructArray = new MyStruct*[1024];
for(long i=0; i<1024; i++){
myStructArray = new MyStruct;
}
so that I can access them by index:
double a = myStructArray[1]->a;
I'm aware of malloc as a simple lump of memory, but don't understand
how it would be aware of the boundaries of each struct and each
element.
Thanks
Steve
I've been working with C++ and Objective-C and I've forgotten how to
allocate memory for an array of structs in C.
Given a struct:
typedef struct {
double a,b,c,d;
long e,f,g,h;
} MyStruct
I want to do the equivalent of :
MyStruct **myStructArray;
myStructArray = new MyStruct*[1024];
for(long i=0; i<1024; i++){
myStructArray = new MyStruct;
}
so that I can access them by index:
double a = myStructArray[1]->a;
I'm aware of malloc as a simple lump of memory, but don't understand
how it would be aware of the boundaries of each struct and each
element.
Thanks
Steve