Is there any reason why you should use MemAlloc when you can just create an array of bytes? You can read from and write to it the same way, you can create a bank from it, etc. -- so why use MemAlloc over a byte array? You even access them nearly the same way (you use [idx]).
Byte array
MemAlloc
So, I'm wondering if there are any advantages to one or the other.
Advantages for MemAlloc:
- As far as I know, it's not controlled by the garbage collector, so you can pass it to an external library and it can free it later. With a Byte array, you would have to reference it somewhere to keep it in memory (or not call FlushMem, and not calling FlushMem would be a bad idea).
- Dereferencing it is fun.
Disadvantages:
- MemAlloc is an ugly function name.
Advantages of the Byte array:
- Controlled by the garbage collector.
Disadvantages:
- You can't dereference it for fun.
So, am I missing anything from those?
Byte array
Local MyData:Byte[128] Print MyData[idx]
MemAlloc
Local MyData:Byte Ptr = MemAlloc( 128 ) Print MyData[idx]
So, I'm wondering if there are any advantages to one or the other.
Advantages for MemAlloc:
- As far as I know, it's not controlled by the garbage collector, so you can pass it to an external library and it can free it later. With a Byte array, you would have to reference it somewhere to keep it in memory (or not call FlushMem, and not calling FlushMem would be a bad idea).
- Dereferencing it is fun.
Disadvantages:
- MemAlloc is an ugly function name.
Advantages of the Byte array:
- Controlled by the garbage collector.
Disadvantages:
- You can't dereference it for fun.
So, am I missing anything from those?