Organizing Structures

You can optimize structures’ efficiency with a little bit of work. This work is related to the order in which you implement members within a structure. For example, consider the following code:

Public Structure VariousMembers    Public Property anInteger As Integer    Public Property aByte As Byte    Public Property aShort As ShortEnd Structure

Notice in which order the members are exposed. Because of their memory allocation in bytes, it’s preferable to expose members in the order of bytes they require. This is a revisited, more efficient version of the structure:

Public Structure VariousMembers    Public Property aByte As Byte    Public Property aShort As Short ...

Get Visual Basic 2015 Unleashed now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.