5 void *sq_vm_malloc(SQUnsignedInteger size);
6 void *sq_vm_realloc(
void *p,SQUnsignedInteger oldsize,SQUnsignedInteger size);
7 void sq_vm_free(
void *p,SQUnsignedInteger size);
9 #define sq_new(__ptr,__type) {__ptr=(__type *)sq_vm_malloc(sizeof(__type));new (__ptr) __type;} 10 #define sq_delete(__ptr,__type) {__ptr->~__type();sq_vm_free(__ptr,sizeof(__type));} 11 #define SQ_MALLOC(__size) sq_vm_malloc((__size)); 12 #define SQ_FREE(__ptr,__size) sq_vm_free((__ptr),(__size)); 13 #define SQ_REALLOC(__ptr,__oldsize,__size) sq_vm_realloc((__ptr),(__oldsize),(__size)); 15 #define sq_aligning(v) (((size_t)(v) + (SQ_ALIGNMENT-1)) & (~(SQ_ALIGNMENT-1))) 45 if(v._size > _allocated) {
48 for(SQUnsignedInteger i = 0; i < v._size; i++) {
49 new ((
void *)&_vals[i]) T(v._vals[i]);
56 for(SQUnsignedInteger i = 0; i < _size; i++)
58 SQ_FREE(_vals, (_allocated *
sizeof(T)));
61 void reserve(SQUnsignedInteger newsize) { _realloc(newsize); }
62 void resize(SQUnsignedInteger newsize,
const T&
fill = T())
64 if(newsize > _allocated)
67 while(_size < newsize) {
68 new ((
void *)&_vals[_size]) T(
fill);
73 for(SQUnsignedInteger i = newsize; i < _size; i++) {
79 void shrinktofit() {
if(_size > 4) { _realloc(_size); } }
80 T& top()
const {
return _vals[_size - 1]; }
81 inline SQUnsignedInteger size()
const {
return _size; }
82 bool empty()
const {
return (_size <= 0); }
83 inline T &push_back(
const T& val = T())
85 if(_allocated <= _size)
87 return *(
new ((
void *)&_vals[_size++]) T(val));
89 inline void pop_back()
91 _size--; _vals[_size].~T();
93 void insert(SQUnsignedInteger idx,
const T& val)
96 for(SQUnsignedInteger i = _size - 1; i > idx; i--) {
97 _vals[i] = _vals[i - 1];
101 void remove(SQUnsignedInteger idx)
104 if(idx < (_size - 1)) {
105 memmove(&_vals[idx], &_vals[idx+1],
sizeof(T) * (_size - idx - 1));
109 SQUnsignedInteger capacity() {
return _allocated; }
110 inline T &back()
const {
return _vals[_size - 1]; }
111 inline T& operator[](SQUnsignedInteger pos)
const{
return _vals[pos]; }
114 void _realloc(SQUnsignedInteger newsize)
116 newsize = (newsize > 0)?newsize:4;
117 _vals = (T*)SQ_REALLOC(_vals, _allocated *
sizeof(T), newsize *
sizeof(T));
118 _allocated = newsize;
120 SQUnsignedInteger _size;
121 SQUnsignedInteger _allocated;
signed char * fill(signed char *first, signed char *last, Value val)
Definition: algorithm.h:168