Vector Class Discussion

 
thread Large Arrays - Bill - 2018-03-14
last reply Large Arrays - Agner - 2018-03-15
 
Large Arrays
Author: Bill Date: 2018-03-14 18:00
Let's say I have a really large main_array of a custom type:
type1 main_array[1500];

type1 is a struct that looks like:

struct type1
{
int m_i1;
int m_i2;

struct levels
{
int x1;
int x2;
int y1;
int y2;
} m_levels[5];
};


So, type1 is 88 bytes, and main_array is 132,000 bytes.

Now, let's say I have another array of a custom type that contains various offsets into main_array to access it's contents. Like this:

type2 access_array[10];

struct type2
{
int m_offset1;
int m_offset2;
int m_offset3;
};


Can I use VCL to optimize walking through access_array to get to the random offsets of main_array?
   
Large Arrays
Author: Agner Date: 2018-03-15 00:55
The elements of a vector must have the same type. All elements will get the same treatment. It is not good to have an array of structures with different kinds of elements that need different treatment.

Your type1 structure is 22 integers and type2 is 30 integers. You can make it an array of all integers, and then mask off elements that need different treatment, but that may be a mess. It is better to reorganize your data if possible so that data that need the same treatment are put together in the same array. For example, put all m_levels in one array and m_i1, m_i2 in another array.