Idea for Limited, but Dynamically Allocated Arrays

Post » Mon Dec 03, 2012 1:19 pm

I was stumbling across potential solutions for speeding up and optimizing code. Actually, my goal was to take advantage of the great user interface of LinkedRefs/FormLists/etc. for the basic laying out of variables for the design process and then have that data all automatically (one-time only) converted into hidden arrays to VASTLY speed things up. One of the problems I've ran into before was how literals were required to declare array length; and I didn't want to unnecessarily allocate more memory than I needed (especially since what I was doing would involve arrays of varied lengths). Anyways, I haven't tested it, as I'm about to go to sleep, but I am wondering if this were actually a possible loophole to solve the issue:

ObjectReference[] Function allocateArray( int tArraySize )	 if ( tArraySize == 0 )		  return new ObjectReference[1]	 elseif( tArraySize == 1 )		  return new ObjectReference[2]	 elseif( tArraySize == 2 )		  return new ObjectReference[3]	 endif	 ;etc	 return newObjectReference[10]EndFunctionObjectReference[] property helloArray autohelloArray = allocateArray( 10 ); Yay now it only can store 10!

Will garbage collection do something weird and eat this or will it actually allocate the correct size and keep (which every other language permits so long as it's a variable in use)?
User avatar
saxon
 
Posts: 3376
Joined: Wed Sep 19, 2007 2:45 am

Return to V - Skyrim