67 return( malloc(size) );
73 return( calloc(num, size) );
79 return( realloc(memblock, new_size) );
103 #else // ifndef _WINDOWS_
107 return( HeapAlloc(GetProcessHeap(), 0, size) );
110 void *
SG_Calloc(
size_t num,
size_t size)
112 return( HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, num * size) );
115 void *
SG_Realloc(
void *memblock,
size_t new_size)
121 return( HeapReAlloc(GetProcessHeap(), 0, memblock, new_size) );
125 return( HeapAlloc(GetProcessHeap(), 0, new_size) );
140 HeapFree(GetProcessHeap(), 0, memblock);
144 #endif // ifndef _WINDOWS_
159 pB = pA + nBytes - 1;
179 int Value = *(
int *)Buffer;
196 *((
int *)Buffer) = Value;
202 double Value = *(
double *)Buffer;
219 *(
double *)Buffer = Value;
236 m_Value_Size =
sizeof(char);
237 m_Growth = TSG_Array_Growth::SG_ARRAY_GROWTH_0;
254 m_Value_Size = Array.m_Value_Size;
255 m_Growth = Array.m_Growth;
257 if( Array.m_nValues > 0 &&
Get_Array(Array.m_nValues) )
259 memcpy(m_Values, Array.m_Values, Array.m_nValues * Array.m_Value_Size);
272 Create(Value_Size, nValues, Growth);
279 m_Value_Size = Value_Size;
312 if( nValues >= m_nValues && nValues <= m_nBuffer )
319 if( nValues < m_nValues && !bShrink )
338 case TSG_Array_Growth::SG_ARRAY_GROWTH_0:
default:
342 case TSG_Array_Growth::SG_ARRAY_GROWTH_1:
343 nBuffer = nValues < 10 ? nValues
344 : nValues < 100 ? (1 + nValues / 10) * 10
345 : nValues < 1000 ? (1 + nValues / 100) * 100
346 : nValues < 10000 ? (1 + nValues / 1000) * 1000
347 : (1 + nValues / 10000) * 10000;
350 case TSG_Array_Growth::SG_ARRAY_GROWTH_2:
351 nBuffer = nValues < 100 ? nValues
352 : nValues < 1000 ? (1 + nValues / 10) * 10
353 : nValues < 10000 ? (1 + nValues / 100) * 100
354 : nValues < 100000 ? (1 + nValues / 1000) * 1000
355 : (1 + nValues / 10000) * 10000;
358 case TSG_Array_Growth::SG_ARRAY_GROWTH_3:
359 nBuffer = nValues < 1000 ? (1 + nValues / 1000) * 1000
360 : nValues < 10000 ? (1 + nValues / 10000) * 10000
361 : nValues < 100000 ? (1 + nValues / 100000) * 100000
362 : (1 + nValues / 1000000) * 1000000;
365 case TSG_Array_Growth::SG_ARRAY_GROWTH_FIX_8 : nBuffer = (1 + nValues / 8) * 8;
break;
366 case TSG_Array_Growth::SG_ARRAY_GROWTH_FIX_16 : nBuffer = (1 + nValues / 16) * 16;
break;
367 case TSG_Array_Growth::SG_ARRAY_GROWTH_FIX_32 : nBuffer = (1 + nValues / 32) * 32;
break;
368 case TSG_Array_Growth::SG_ARRAY_GROWTH_FIX_64 : nBuffer = (1 + nValues / 64) * 64;
break;
369 case TSG_Array_Growth::SG_ARRAY_GROWTH_FIX_128 : nBuffer = (1 + nValues / 128) * 128;
break;
370 case TSG_Array_Growth::SG_ARRAY_GROWTH_FIX_256 : nBuffer = (1 + nValues / 256) * 256;
break;
371 case TSG_Array_Growth::SG_ARRAY_GROWTH_FIX_512 : nBuffer = (1 + nValues / 512) * 512;
break;
376 if( nBuffer == m_nBuffer )
384 void *Values =
SG_Realloc(m_Values, nBuffer * m_Value_Size);
416 return(
Set_Array(m_nValues + nValues) );
421 return(
Set_Array(m_nValues + 1, pArray) );
427 return( m_nValues > 0 ?
Set_Array(m_nValues - 1, bShrink) :
false );
432 return( m_nValues > 0 ?
Set_Array(m_nValues - 1, pArray, bShrink) :
false );
438 if( Index >= 0 && Index < m_nValues )
440 if( Index < m_nValues - 1 )
442 char *ip = (
char *)m_Values + Index * m_Value_Size;
char *jp = ip + m_Value_Size;
444 for(
sLong i=Index, j=Index+1; j<m_nValues; i++, j++, ip+=m_Value_Size, jp+=m_Value_Size)
446 for(
size_t k=0; k<m_Value_Size; k++)
471 m_Array.
Create(Array.m_Array);
479 m_Array.
Create(
sizeof(
void *), nValues, Growth);
502 if(
Add(Array[i]) ==
false )
518 (*this)[Index] = (*this)[i];
534 if( Value == (*
this)[i - 1] &&
Del(i - 1) )
553 m_Array.
Create(Array.m_Array);
561 m_Array.
Create(
sizeof(
int), nValues, Growth);
584 if(
Add(Array[i]) ==
false )
614 m_Array.
Create(Array.m_Array);
645 if(
Add(Array[i]) ==
false )
697 return(
Set_Data(Buffer.m_Data, Buffer.m_Size) );
738 else if( Size > m_Size || (Size < m_Size && bShrink) )
740 char *Data = (
char *)
SG_Realloc(m_Data, Size *
sizeof(
char));
757 if( !Data || !Size || !
Set_Size(Size, bShrink) )
762 memcpy(m_Data, Data, m_Size);
820 return(
Add((
void *)Bytes, nBytes,
false) );
858 bool CSG_Bytes::_Inc_Array(
int nBytes)
860 if( m_nBuffer < m_nBytes + nBytes )
862 int nBuffer = m_nBuffer + nBytes + 1024;
863 BYTE *Bytes = (BYTE *)
SG_Realloc(m_Bytes, nBuffer *
sizeof(BYTE));
889 if( _Inc_Array(Bytes.m_nBytes) )
891 memcpy(m_Bytes, Bytes.m_Bytes, m_nBytes);
907 return(
Add(Bytes.m_Bytes, Bytes.m_nBytes,
false) );
913 int Offset = m_nBytes;
915 if( _Inc_Array(nBytes) )
917 memcpy(m_Bytes + Offset, Bytes, nBytes);
940 case '1':
return( 1 );
941 case '2':
return( 2 );
942 case '3':
return( 3 );
943 case '4':
return( 4 );
944 case '5':
return( 5 );
945 case '6':
return( 6 );
946 case '7':
return( 7 );
947 case '8':
return( 8 );
948 case '9':
return( 9 );
949 case 'a':
case 'A':
return( 10 );
950 case 'b':
case 'B':
return( 11 );
951 case 'c':
case 'C':
return( 12 );
952 case 'd':
case 'D':
return( 13 );
953 case 'e':
case 'E':
return( 14 );
954 case 'f':
case 'F':
return( 15 );
970 for(
int i=0; i<m_nBytes; i++)
985 for(
size_t i=0; i<HexString.
Length(); i+=2, s+=2)
1019 for(
int i=0; i<m_nBytes; i++)
1021 delete(m_pBytes[i]);
1037 if( m_nBytes >= m_nBuffer )
1050 return( m_pBytes[m_nBytes++] =
new CSG_Bytes );