Page 1 of 1

Posted: Tue Dec 10, 2002 6:04 pm
by BackupUser
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

Posted: Tue Dec 10, 2002 6:14 pm
by BackupUser
Restored from previous forum. Originally posted by Pupil.

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]

Something like the above should work..

Posted: Wed Dec 11, 2002 10:23 am
by BackupUser
Restored from previous forum. Originally posted by Froggerprogger.

Code: Select all

CopyMemory(FSOUND_DSP_GetSpectrum(), hfft.fftarray, 4*512)
works, now - without any pointers. I tried it before, but my mistake was somewere else in code. :)

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)
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