D - Interfacing to C: Declaring a pointer to an array of pointers
- Russell Lewis (9/9) Sep 11 2002 My D-space code makes use of an array of pointers. I want to allocate
- Burton Radons (5/16) Sep 11 2002 MyType *[] *ptr = (MyType *[] *) new void *[1];
- Russell Lewis (5/26) Sep 12 2002 Actually, the size of an array reference is 8 bytes, right? So it
- Burton Radons (9/40) Sep 12 2002 Ah right (I knew my brain had melted), then:
- Walter (6/15) Sep 12 2002 What new is doing is attempting to allocate a dynamic array, and the
My D-space code makes use of an array of pointers. I want to allocate this array on the heap (not the stack), cast the address to a void pointer, and send it through some C code. Later, the C code will give the pointer back to me, I will cast it back and get access to my array. I can declare the pointer-to-array-to-pointers variable, but am having trouble using "new" to allocate the memory: MyType*[]* ptr = new MyType*[]; Looks like the parser doesn't recognize []'s in the 'new' expression. How should I do this?
Sep 11 2002
Russell Lewis wrote:My D-space code makes use of an array of pointers. I want to allocate this array on the heap (not the stack), cast the address to a void pointer, and send it through some C code. Later, the C code will give the pointer back to me, I will cast it back and get access to my array. I can declare the pointer-to-array-to-pointers variable, but am having trouble using "new" to allocate the memory: MyType*[]* ptr = new MyType*[]; Looks like the parser doesn't recognize []'s in the 'new' expression. How should I do this?MyType *[] *ptr = (MyType *[] *) new void *[1]; That should do it, unless if my brain has melted and I've written gibberish. It's definitely a problem inherited from DMD; new needs some work.
Sep 11 2002
Burton Radons wrote:Russell Lewis wrote:Actually, the size of an array reference is 8 bytes, right? So it should be: = (MyType*[]*) new void*[2]; Then I have to initialize the array...My D-space code makes use of an array of pointers. I want to allocate this array on the heap (not the stack), cast the address to a void pointer, and send it through some C code. Later, the C code will give the pointer back to me, I will cast it back and get access to my array. I can declare the pointer-to-array-to-pointers variable, but am having trouble using "new" to allocate the memory: MyType*[]* ptr = new MyType*[]; Looks like the parser doesn't recognize []'s in the 'new' expression. How should I do this?MyType *[] *ptr = (MyType *[] *) new void *[1]; That should do it, unless if my brain has melted and I've written gibberish. It's definitely a problem inherited from DMD; new needs some work.
Sep 12 2002
Russell Lewis wrote:Burton Radons wrote:Ah right (I knew my brain had melted), then: = new MyType *[] [1]; Should be the right way. That fails, and it's a parsing bug. The two void pointers will be initialised to null, so it's all set up as an array. But it's not portably guaranteed to be an array. The full, correct way to do it that works is: alias MyType *[] MyTypePtrArray; = new MyTypePtrArray [1];Russell Lewis wrote:Actually, the size of an array reference is 8 bytes, right? So it should be: = (MyType*[]*) new void*[2]; Then I have to initialize the array...My D-space code makes use of an array of pointers. I want to allocate this array on the heap (not the stack), cast the address to a void pointer, and send it through some C code. Later, the C code will give the pointer back to me, I will cast it back and get access to my array. I can declare the pointer-to-array-to-pointers variable, but am having trouble using "new" to allocate the memory: MyType*[]* ptr = new MyType*[]; Looks like the parser doesn't recognize []'s in the 'new' expression. How should I do this?MyType *[] *ptr = (MyType *[] *) new void *[1]; That should do it, unless if my brain has melted and I've written gibberish. It's definitely a problem inherited from DMD; new needs some work.
Sep 12 2002
"Russell Lewis" <spamhole-2001-07-16 deming-os.org> wrote in message news:3D7FA2FB.2030106 deming-os.org...My D-space code makes use of an array of pointers. I want to allocate this array on the heap (not the stack), cast the address to a void pointer, and send it through some C code. Later, the C code will give the pointer back to me, I will cast it back and get access to my array. I can declare the pointer-to-array-to-pointers variable, but am having trouble using "new" to allocate the memory: MyType*[]* ptr = new MyType*[]; Looks like the parser doesn't recognize []'s in the 'new' expression. How should I do this?What new is doing is attempting to allocate a dynamic array, and the trailing [] doesn't have a dimension in it. You could try: alias MyType*[] foo; foo *ptr = new foo;
Sep 12 2002