Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

DarkBASIC Discussion / Copy memory into memblock?

Author
Message
TheComet
12
Years of Service
User Offline
Joined: 18th Oct 2007
Location: I`m under ur bridge eating ur goatz.
Posted: 25th Dec 2011 17:30
This is for the vertex challenge in DBC. I have a pointer telling me where the memory is located, and I want to somehow copy that memory into a memblock. Da codez:



Now I have to copy the 256 bytes that are at the pointer ffthandle(0) into memblock 1 which is at pointer spectrum(0) to get my FFT data. Is this possible?

TheComet


Don't click.
Latch
14
Years of Service
User Offline
Joined: 23rd Jul 2006
Location:
Posted: 26th Dec 2011 01:55 Edited at: 1st Jan 2012 23:37
Hi, TheComet,

It's possible, but you'll need help from a DLL function call. If the DLL you are using doesn't have a copy memory function built in, one can be made in a separate DLL. I went ahead and knocked together a copy memory call in a dll. It's just bare bones - it does very little checking - it will only check if the pointers are NULL.

It's the USERS responsibility to know that the target and source memory the pointers point to is allocated to the correct size and you aren't trying to copy more bytes than are available or receivable. The dll is attached.

The call is as follows



If successful, then resultptr should be equal to targetptr otherwise -1 is returned.

For your code it might look like:



Enjoy your day.

Attachments

Login to view attachments
Benjamin
17
Years of Service
User Offline
Joined: 24th Nov 2002
Location: France
Posted: 2nd Jan 2012 20:37
One of the system libraries (kernel32 to be exact) provides a function that can be used to copy memory:



It's the closest you'll find for a function that does a simple memory copy, since the most basic routines are implemented inline rather than in a library.



Support a charitable indie game project!
Latch
14
Years of Service
User Offline
Joined: 23rd Jul 2006
Location:
Posted: 3rd Jan 2012 01:41 Edited at: 3rd Jan 2012 01:57
I thought the RtlMoveMemory function only moves 4 byte blocks at a time, but it seems to work with any length. Nice.

Enjoy your day.
Benjamin
17
Years of Service
User Offline
Joined: 24th Nov 2002
Location: France
Posted: 3rd Jan 2012 02:05
Quote: "I think the RtlMoveMemory function only moves 4 byte blocks at a time."


Not as far as I know.



Support a charitable indie game project!

Login to post a reply

Server time is: 2020-08-15 11:38:09
Your offset time is: 2020-08-15 11:38:09