Pointers / Direct Memory Access

BlitzPlus Forums/BlitzPlus Programming/Pointers / Direct Memory Access

uwdesign(Posted 2003) [#1]
This has prolly been asked before, but i'll ask again anyway :)

Currently I've using BBbanks to alloc/deallocate slabs of memory for various structures. This is ok most of the time, however ideally what i'm interested in is there a way to poke/peek directly to memory based purely upon an address, rather than using BBbanks ?


Seldon(Posted 2003) [#2]
When you create a bank you get a memory area that has an address in memory. So, there's no difference. In modern operating systems you can't poke upon an address directly. The OS doesn't let you do that, unless you're writing a driver, a VXD in Win9x or whatever must run in ring-0) and it's dangerous to do that as you could damage the system and you most likely would lose compatibility with further releases of the OS.

Ciao.


DrMartin(Posted 2003) [#3]
Yes, absolutely correct. A bank is as close to writing directly to the memory you can get. Have you run into any limitations with the BBbanks?


uwdesign(Posted 2003) [#4]
Thanks guys

Although i'm not suggesting poking memory in any type of random fashion, i'm not that green. I merely want to alloc a block, and then poke/peek the actual address of the element i want.. Currently in my structures I have to store bank handles + address offsets. Pretty wasteful..

We've since just tried building a little plug in for this, So this should work fine..


Seldon(Posted 2003) [#5]
By creating a bank, you do allocate a block of memory. To poke/peek an element, add the offset required from the first element.

I hope this can help:

bank=CreateBank(9) ;You get a memory block of 9 bytes
PokeByte bank,0,1 ;First byte of the block set to 1
PokeByte bank,8,2 ;9th byte of the block set to 2

As I said, you can't poke an actual address, as Windows manages the memory for you (and it could happen it allocates a block of virtual-memory in the hard-disk).
The only chance is using the API function GlobalAlloc() with GMEM_FIXED flag. Then you simply cast the return value to a pointer. Of course, I doubt Blitz Poke/Peek can work with this as they need an handle to a Blitz bank.


uwdesign(Posted 2003) [#6]
To reiterate, I'm more than familiar with BBbanks.

However the 'bank handle" plus "address" (2 longs) set up is not ideal, rather wasteful, for the situation I had in mind.

The problem has been solved however, by building our own plug in bank command set.