Resizing a global memory block

Folks - In my module’s Properties, have declared mymemoryblock as a global memory block: mymemoryblock as memoryblock

Now I need to resize it. The Xojo documentation indicates
mymemoryblock.size = 5000
but this gives “NilObjectException”
Ouch!

Any ideas?

You have declared your memoryblock but have you created it yet?

Thanks, Kevin.

When I tried
Var mymemoryblock as new memoryblock (5000)
Xojo created a new local memory block, so how do I create the global one?

Var declares a local variable. Since you have already declared your global property you can just do:

mymemoryblock as new memoryblock (5000)

I think you mean:

mymemoryblock = new MemoryBlock( 5000 )

I did.

if mymemoryblock is a global variable,

You might initialise it in app.open using

mymemoryblock = new MemoryBlock( 26000 )
and then use it.

Later, if you want a smaller one and don’t care about the content, you can do this somewhere else:

mymemoryblock = new MemoryBlock( 5000 )

but if you want the memoryblock to change size and keep the contents that’s when you
can try using .size

mymemoryblock.size = 5000

If the new size is bigger than the old, it should contain the same data (Xojo will have done this by allocating new memory and copying A to B
Not sure what they do for a smaller one, but in both cases you should not (IMO) rely on anything that stored the address in memory of the memoryblock before the resize.

Pretty sure it’s truncated.

Thanks, Kevin, Kem and Jeff.
mymemoryblock = new MemoryBlock( 5000 )
works! I would never have guessed this from my reading of the Xojo documentation. Perhaps Xojo should change the documentation into a Wiki so that useful information can be added to it (and obsolete information removed) by Xojo users.

Considering they changed away from that over the last few years, I doubt it.