Redimension in Structure? and more

Just starting out? Need help? Post your questions and find answers here.
timfrombriz
User
User
Posts: 13
Joined: Sat May 21, 2011 9:59 am

Redimension in Structure? and more

Post by timfrombriz »

Got a couple questions, Im transitioning from VB6 and getting adjusted to the coding style.

In VB, you could declare say...

Public Type FontStruct
FontSprite(33 To 127) As Long
Mask() As Byte
End Type

Public Font(255) as FontStruct

Now Im unsure about the FontStruct Structure, it has a static array of Longs with a lower boundary of 33, and Mask which is not dimensioned at declare (ie. unallocated), but within the code will be redimensioned with redim.

This is the closest I come up with with PureBasic...

Structure FontStruct
FontSprite.l[127]
Mask.c[0]
EndStructure

Global Dim Font.FontStruct(255)

I know in VB6 the 'Mask' bytes arent stored directly in FontStruct, rather a pointer, which means the Mask array can be redimensioned easily, Im presuming this isnt the case with PureBasic? Thus meaning in vb6, the Mask can be redimensioned by "Redim Font(26).Mask(255)" without reallocating the entire Font array.

Is it possible to have a redimensional Array within a structure, and also to specify a lower boundary?

Thanks for your time :)
Trond
Always Here
Always Here
Posts: 7446
Joined: Mon Sep 22, 2003 6:45 pm
Location: Norway

Re: Redimension in Structure? and more

Post by Trond »

If you use normal arrays you can change the number of elements at runtime:

Code: Select all

Structure FontStruct
  Array FontSprite.l(127)
  Array Mask.a(0)
EndStructure

Dim f.FontStruct(255)
Dim f(26)\Mask(255)
timfrombriz
User
User
Posts: 13
Joined: Sat May 21, 2011 9:59 am

Re: Redimension in Structure? and more

Post by timfrombriz »

Ok thanks Trond. Still got these questions outstanding...

Is it possible to set a lower boundary on a array

With Trond's code above, does this redimension the entire FontStruct structure, or does PureBasic store this array as a pointer within FontStruct, thus only allocating the element being redimensioned?
Trond
Always Here
Always Here
Posts: 7446
Joined: Mon Sep 22, 2003 6:45 pm
Location: Norway

Re: Redimension in Structure? and more

Post by Trond »

timfrombriz wrote:Is it possible to set a lower boundary on a array
No.

Only f(26)\Mask is changed, not f(25) or any other element.
timfrombriz
User
User
Posts: 13
Joined: Sat May 21, 2011 9:59 am

Re: Redimension in Structure? and more

Post by timfrombriz »

Sorry, I must not be making myself clear...

Code: Select all

Structure FontStruct
  Array FontSprite.l(33 to 127)
  Array Mask.a(0)
EndStructure

Dim f.FontStruct(255)
Dim f(26)\FontSprite(33)
Lower Boundary, meaning the first element in the array is 33 not 0. Is it possible to set a lower boundary in an array declare.

In memory, are the Mask and FontSprite arrays stored within the FontStruct, or as a pointer to their own memory area. Meaning that when...

Code: Select all

Dim f(26)\FontSprite(33)
is called, does it reallocates the entire 255 sized f structure because the FontSprite array is stored within the structures memory allocation or does it resize the FontSprite array and adjust a pointer within the f(26) structure to redirect to the newly sized FontSprite.
Trond
Always Here
Always Here
Posts: 7446
Joined: Mon Sep 22, 2003 6:45 pm
Location: Norway

Re: Redimension in Structure? and more

Post by Trond »

No, you can't set the lower boundary.

Yes, it's a pointer.
Post Reply