Arrays

Olli Aalto oaalto at gmail.com
Wed Jan 10 01:52:32 PST 2007


Hi!

I've been playing with arrays lately. Static arrays, 2/3/4 dimensional 
arrays and dynamic arrays.

First I'd like to ask if it's safe to do this:

int[] getIntArrayWithLengthOf2()
{
	int[] array = new int[2];
	array[] = 2;
	return array;
}

some scope
{
	int[2] array2 = getIntArrayWithLengthOf2();
}

It seem to work, but what about memory? How's it handled? Do I need to 
delete it if I don't want the GC take care of it? Or does the array2 go 
out of scope when leaving the "some scope"?
What if the array2 is a class field?

I'm asking this because I'm working with static arrays mostly, but as I 
can't return them from functions I need to return a dynamic array 
instead. Then I'm assigning it to a static array. Is this wise?

Thanks,

O.


More information about the Digitalmars-d-learn mailing list