void AllocIfRequired(int indexToAdd)
{
if (indexToAdd < m_allocated_vertices)
{
return;
}
#if DEBUG
int nrounds = 0;
#endif
while (indexToAdd >= m_allocated_vertices)
{
#if DEBUG
if (nrounds > 0)
{
}
nrounds++;
#endif
//newsize is LARGER than original ****
int newSize = ((indexToAdd + 257) / 256) * 256; //calculate new size in single round
//int newSize = m_allocated_vertices + 256; //original
//--------------------------------------
double[] new_xy = new double[newSize << 1];
byte[] newCmd = new byte[newSize];
if (m_coord_xy != null)
{
//copy old buffer to new buffer
int actualLen = m_num_vertices << 1;
//-----------------------------
//TODO: review faster copy
//-----------------------------
unsafe
{
//unsafed version?
fixed (double* srcH = &m_coord_xy[0])
{
System.Runtime.InteropServices.Marshal.Copy(
(System.IntPtr)srcH,
new_xy, //dest
0,
actualLen);
}
fixed (byte* srcH = &m_cmds[0])
{
System.Runtime.InteropServices.Marshal.Copy(
(System.IntPtr)srcH,
newCmd, //dest
0,
m_num_vertices);
}
}
//------------------------------------
//line by line version
//for (int i = actualLen - 1; i >= 0; )
//{
// new_xy[i] = m_coord_xy[i];
// i--;
// new_xy[i] = m_coord_xy[i];
// i--;
//}
//for (int i = m_num_vertices - 1; i >= 0; --i)
//{
// newCmd[i] = m_cmds[i];
//}
}
m_coord_xy = new_xy;
m_cmds = newCmd;
m_allocated_vertices = newSize;
}
}
//----------------------------------------------------------