Restored from previous forum. Originally posted by Froggerprogger.
I've got the following problem:
A function creates an array with 500 elements and returns a pointer to it.
[here: harray = FSOUND_DSP_GetSpectrum()]
How can I get the values into my own array to work on with them now?
I declared my array with DIM Array.f(500).
I tried it with CopyMemory()in all varieties, but without having a bit of an idea, so I think a good hint might be better than trying out a lot of stuff!!
Purebasic - what a nice name for a girl-friend
how to manage function-returned pointer to array?
-
BackupUser
- PureBasic Guru

- Posts: 16777133
- Joined: Tue Apr 22, 2003 7:42 pm
Restored from previous forum. Originally posted by Pupil.
You could easily solve this with a structure, there may be other ways too..
Something like the above should work..
You could easily solve this with a structure, there may be other ways too..
Code: Select all
Structure MyStruct
array.f[0]
EndStructure
*ptr.MyStruct = FSOUND_DSP_GetSpectrum() ; this would be one way
; another way would be if you want a copy of the array
*ptr.MyStruc = AllocateMemory(0, 4*500, 0)
CopyMemory(FSOUND_DSP_GetSpectrum(), *ptr, 4*500)
; access structure like this
; First item in array:
value.f = *ptr\array[0]
-
BackupUser
- PureBasic Guru

- Posts: 16777133
- Joined: Tue Apr 22, 2003 7:42 pm
Restored from previous forum. Originally posted by Froggerprogger.
works, now - without any pointers. I tried it before, but my mistake was somewere else in code. 
none of these versions works - and now i understand, why!
CopyMemory expects the memoryIDs, not the values from the pointers.
Thanks a lot for inspiration
nothing is for nothing.
Purebasic - what a nice name for a girl-friend
Code: Select all
CopyMemory(FSOUND_DSP_GetSpectrum(), hfft.fftarray, 4*512)Code: Select all
*ptr.MyStruct = FSOUND_DSP_GetSpectrum() ; this would be one way; another way would be if you want a copy of the array
*ptr.MyStruc = AllocateMemory(0, 4*500, 0)
CopyMemory(FSOUND_DSP_GetSpectrum(), *ptr, 4*500)CopyMemory expects the memoryIDs, not the values from the pointers.
Thanks a lot for inspiration
nothing is for nothing.
Purebasic - what a nice name for a girl-friend