Dangerous optimization?
Blitz3D Forums/Blitz3D Programming/Dangerous optimization?
| ||
In my persuit to optimize certain intensive routines within an inch of their lives, I've been assigning ImageBuffer() handles to variables and then using the variable to SetBuffer/LockBuffer etc. Global image1 = CreateImage(100,100) Global IB_image1 = ImageBuffer(image1) . . . SetBuffer IB_image1 Rect 0,0,10,10 Do you think this could be unsafe? I guess what I'm really asking is: Once an image is loaded/created, is it guaranteed to remain in the same place in VRAM until it's released? |
| ||
Honestly, I think the only person that knows the answer to that would be Mark. However, you could set up a test of some form, to determine whether an image buffer's location ever changes. I think the worst thing that would happen is your program will crash with an invalid buffer error. Personally I would find it more wasteful to carry around both an image handle and the handle to its buffer, as it seems you need both for different operations. |
| ||
From memory the imagebuffer function provides an indirect reference anyway, i.e. It does not provide a reference to the actual buffer, but a structure that contains that information along with other stuff describing the pixel format and so on. So I think you are safe enough. |
| ||
Storm: I haven't tried a test as such, but I've been using the method on several buffers in my app over the last week and it's never caused a crash. I was just thinkning it might bide it's time and then jump up and bite me in the ***, when I least expect it. :) DJW: Thinking about it, I pretty sure you're right. Most/all of blitz's resource handles seem to point to internal structures, I think. I just thought I'd ask in case I was making a huge blunder in my coding. :P |