How are handles implemented internally in PB? I would like to provide an "object handle" type interface in a dynamic library I am creating, but I noticed that if I use redim to resize an array of structures, the contents are trashed. Is there a way to do this sort of thing and not have to copy all the data to a new array?
Maybe dynamically allocate memory blocks and treat it as an array somehow?
Implementing handles
From the manual
*ByteArray\b = 127
etc
You can just allocate a memory block using allocatememory and use pointer arithmatic on it.ReDim is used to 'resize' an already declared array while preserving its content. The new size can be larger or smaller, but the number of dimension of the array can not be changed.
*ByteArray\b = 127
etc
Paul Dwyer
“In nature, it’s not the strongest nor the most intelligent who survives. It’s the most adaptable to change” - Charles Darwin
“If you can't explain it to a six-year old you really don't understand it yourself.” - Albert Einstein
“In nature, it’s not the strongest nor the most intelligent who survives. It’s the most adaptable to change” - Charles Darwin
“If you can't explain it to a six-year old you really don't understand it yourself.” - Albert Einstein
Yes I ReDim structured arrays all the time and the contents have never been trashed yet!
E.g.
E.g.
Code: Select all
Dim a.point(10)
a(1)\x = 20
Debug a(1)\x
ReDim a.point(100)
Debug a(1)\x
I may look like a mule, but I'm not a complete ass.
-
blueapples
- User

- Posts: 19
- Joined: Mon Oct 03, 2005 10:00 am
Thinking of a different language?
Some basics have redim clear the array unless the "Preserve" keyword is used. PB clears the array if Dim is used on it again.
amounts to the same thing I guess
Some basics have redim clear the array unless the "Preserve" keyword is used. PB clears the array if Dim is used on it again.
amounts to the same thing I guess
Paul Dwyer
“In nature, it’s not the strongest nor the most intelligent who survives. It’s the most adaptable to change” - Charles Darwin
“If you can't explain it to a six-year old you really don't understand it yourself.” - Albert Einstein
“In nature, it’s not the strongest nor the most intelligent who survives. It’s the most adaptable to change” - Charles Darwin
“If you can't explain it to a six-year old you really don't understand it yourself.” - Albert Einstein


