Why doesn't this give a Unhandled Memory Exception

BlitzMax Forums/BlitzMax Programming/Why doesn't this give a Unhandled Memory Exception

Leiden(Posted 2006) [#1]
I've allocated 1000000 bytes but Im able to access 3471 bytes more than what I allocated :/

Global pMemory:Byte Ptr = MemAlloc(1000000)
pMemory[0] = 255
pMemory[1003471] = 255
Print pMemory[1003471]



tonyg(Posted 2006) [#2]
Haven't you simply put the byte address of the first byte allocated into a byte ptr. The byte ptr can point anywhere you want from there.


Dreamora(Posted 2006) [#3]
You won't se a problem as long as the pointed memory isn't protected. In this case you will run into a segmentation fault or "reasonless" crash.

MemAlloc is not controlled by the GC and thus does not raise the normal exceptions, sorry. (there was a MemAlloc version that was GC handled, don't know if it still exists)


N(Posted 2006) [#4]
(there was a MemAlloc version that was GC handled, don't know if it still exists)


Was called GCMalloc, it was removed. Better to just use banks now, since they're practically the same thing only with a public interface.


Leiden(Posted 2006) [#5]
Why is it still printing the correct value? And if you change the two 1003471's to 1003472's it gives a Unhandled Memory Exception.


N(Posted 2006) [#6]
Because it's unprotected memory that you're writing to, and unless another process changes it within the incredibly small amount of time between the few instructions for those two lines it will still be the same value when you print it.

As for incrementing the pointer, that probably means you're writing to protected memory.


Leiden(Posted 2006) [#7]
That makes sense, Thanks.