Being naughty
BlitzMax Forums/BlitzMax Beginners Area/Being naughty
| ||
Hi, I have an integer variable which is an address in memory. I'd like to write values to this area of memory. i.e. like an array but not using an array Jim |
| ||
Use a bank? http://www.blitzbasic.com/bmdocs/command_list_2d_cat.php?show=Banks Last edited 2011 |
| ||
Get the other program that is sending you this to send it as a Byte Ptr? |
| ||
You can simply cast it to a byte pointer, can't you? I'm sure I do that with the window handle between the Windows API and TV3D. And, of course, you can address pointer just like arrays. Last edited 2011 |
| ||
I'm not sure how to use ptr. Global data = 'address' then what? I'd like to write at address, address+1, address+2, etc Jim |
| ||
Some info on what you are doing could be helpful. Where is this address coming from?? If it's from an external source, it should send it to you in a better format than just an integer. Casting between integers and pointer types is not really a good idea, as the size of the pointer depends upon the architecture and might be <> 32-bit int. Not a big deal for BM which will probably always be 32-bit, but it's the principle. (I've read of people doing this in serious business projects and causing headaches for people who need to fix it after them!)SuperStrict Local address:Int = 23432 'danger, will access arbitrary memory Local smallpointer:Byte Ptr = Byte Ptr(address) Local bigpointer:Int Ptr = Int Ptr(address) 'each element is 1 byte of memory smallpointer[0] = 5 smallpointer[1] = 5 smallpointer[2] = 5 smallpointer[3] = 5 'each element is 4 bytes of memory bigpointer[0] = 5 bigpointer[1] = 5 bigpointer[2] = 5 bigpointer[3] = 5 Last edited 2011 |
| ||
Thanks guys, was trying to access a texture but it is not working. I'd like to create textures on the fly but normal methods are so slow. Thanks again Jim |
| ||
Like pixmaps and stuff? I don't think operations on them can ever be fast, as the updated pixmap must be reloaded to graphics memory after each operation. |
| ||
Yeah, if you're retrieving the address in video memory, you'll probably do nothing at all, unless the drivers are a bit gung-ho in which case you might well crash the driver and bring the OS down with it. If you're retrieving the address in system memory, you would still need a way to upload it back to the card again. Perhaps that a look at the normal methods and see if they can't be sped up by (for instance) not using mip maps or something. I was going to suggest compression, but I don't think compressed textures *can* be modified so that's probably out. Last edited 2011 |
| ||
you could draw to the screen, and then grabimage |
| ||
Not sure if this helps, but maybe you can look into using shaders? http://www.blitzmax.com/Community/posts.php?topic=85263 |
| ||
mypointer:int ptr=int ptr (address) address[0]=valueAssuming 'address' is the variable you are receiving with the address, something like this should work. No blitz here, so untested. As you can see, you just use the pointer with array indexing like a plain old array. Last edited 2011 |
| ||
The gotcha here is accessing a texture. This lives (typically) in vram, not system memory. This puts it out of reach for any standard operation. The down side to modern architectures with all their graphically accelerated voodoo is that we no longer actually draw pixel by pixel, even when we think we do, it's all obfuscated behind the GPU interface which is generally accessed through opengl or directx (for the same reasons we use blitz on top of opengl/directx, talking at a lower level is "annoying" and every level down you get it's that much more annoying). There are plenty of ways to update a texture, but they all have drawbacks (which is why there isn't one "best" way). If you can provide details on what you actually want to do perhaps someone can suggest an appropriate method. |
| ||
If you want to do manipulate textures etc then shaders are the better modern way to go - Its one the fundamental principles of programming the graphics card - to manipulate the vertices, and in your case, the textures on the fly. After all, this is one the many reasons modern graphics cards were made programmable. Its the future and definately a programming shift thats going to stay - at least until realtime ray tracing becomes realistic in the mainstream. |