Slicing is???

BlitzMax Forums/BlitzMax Beginners Area/Slicing is???

PowerPC603(Posted 2005) [#1]
Hi,

I know slicing, because I've used it in my project.

What I wanted to know:
Does slicing just create a new array and copy the contents of all indexes from the old array to the new array, and dereference the old array, so it can be flushed at the next FlushMem,

or

does the slicing just resize the allocated memory for the array (so it appears that the array has been resized)?

I ran a small testprogram and it appears that it's the first option.
Just asking to be sure.
Local test[]

FlushMem
Print MemAlloced()

test = test[..1000]

Print MemAlloced()
FlushMem
Print MemAlloced()

test = test[..2000]

Print MemAlloced()
FlushMem
Print MemAlloced()


I wanted this to know, because I wanted to start with 3D-graphics (and models), but there's no 3D-module yet.
So I could convert my code (for loading data into memory from a datafile) to B3D code and the loading routines use slicing.


Dreamora(Posted 2005) [#2]
It is both.

If you assign it to itself it resizes the array, if you assign it to a
local test1[]
test1 = test[..200]

it will copy the first 200 elements from test into test1


ImaginaryHuman(Posted 2005) [#3]
Does it just resize or does it create a new object and point the array pointer to it, thus leaving the old object to be flushed?


FlameDuck(Posted 2005) [#4]
Does it just resize or does it create a new object and point the array pointer to it, thus leaving the old object to be flushed?
Does it make a difference?

I assume it makes a new "object" as that's likely to be faster.


Drago(Posted 2005) [#5]
it makes a new object, you should probably call flushmem after doing it to clean up the memory of the old one.