/** free the blob's memory */ FORCEINLINE void Free() { if (Capacity() > 0) { RawFree(&Hdr()); InitEmpty(); } }
/** free the blob's memory */ inline void Free() { if (Capacity() > 0) { RawFree(&Hdr()); InitEmpty(); } }
T& Vector<T>::GrowAdd(const T& x) { T *prev = vector; Grow(); T *q = Rdd(); DeepCopyConstruct(q, x); RawFree(prev); return *q; }
T& Vector<T>::GrowAddPick(pick_ T& x) { T *prev = vector; Grow(); T *q = Rdd(); ::new(q) T(x); RawFree(prev); return *q; }
void Vector<T>::InsertPick(int i, pick_ Vector<T>& v) { Chk(); v.Chk(); ASSERT(!vector || v.vector != vector); if(v.items) { RawInsert(i, v.items); memcpy(vector + i, v.vector, sizeof(T) * v.items); } RawFree(v.vector); SetPicked(v); }
void Vector<T>::SetCountR(int n, const T& init) { Chk(); ASSERT(n >= 0); if(n == items) return; if(n < items) DestroyArray(vector + n, vector + items); else if(n > alloc) { T *prev = vector; ReAlloc(alloc + ntl_max(alloc, n - items)); DeepCopyConstructFill(vector + items, vector + n, init); RawFree(prev); } else DeepCopyConstructFill(vector + items, vector + n, init); items = n; }
void Vector<T>::RawInsert(int q, int count) { ASSERT(count >= 0); ASSERT(q >= 0 && q <= items); if(!count) return; if(items + count > alloc) { T *newvector = RawAlloc(alloc = alloc + ntl_max(alloc, count)); if(vector) { memcpy(newvector, vector, q * sizeof(T)); memcpy(newvector + q + count, vector + q, (items - q) * sizeof(T)); RawFree(vector); } vector = newvector; } else memmove(vector + q + count, vector + q, (items - q) * sizeof(T)); items += count; }
/** reallocate blob data if needed */ void SmartAlloc(size_t new_size) { if (Capacity() >= new_size) return; /* calculate minimum block size we need to allocate * and ask allocation policy for some reasonable block size */ new_size = AllocPolicy(header_size + new_size + tail_reserve); /* allocate new block and setup header */ BlobHeader *tmp = RawAlloc(new_size); tmp->items = Length(); tmp->capacity = new_size - (header_size + tail_reserve); /* copy existing data */ if (tmp->items != 0) memcpy(tmp + 1, data, tmp->items); /* replace our block with new one */ if (Capacity() > 0) RawFree(&Hdr()); Init(tmp); }
void Vector<T>::Free() { if(vector && items >= 0) DestroyArray((T *)vector, (T *)vector + items); RawFree(vector); }
static IDL_VPTR IDLOldRawRead(int argc,IDL_VPTR *argv) { int s=0; IDL_VPTR vprm=NULL,vraw=NULL;; IDL_FILE_STAT stat; struct OldRawIDLFp *irawfp; struct OldRawFp rawfp; struct RadarIDLParm *iprm=NULL; struct RawIDLData *iraw=NULL; struct RadarParm *prm=NULL; struct RawData *raw=NULL; FILE *ffp=NULL,*ifp=NULL; IDL_ENSURE_STRUCTURE(argv[0]); IDL_EXCLUDE_EXPR(argv[1]); IDL_EXCLUDE_EXPR(argv[2]); irawfp=(struct OldRawIDLFp *) argv[0]->value.s.arr->data; s=IDL_FileEnsureStatus(IDL_MSG_RET,irawfp->rawunit,IDL_EFS_USER); if (s==FALSE) { s=-1; return (IDL_GettmpLong(s)); } IDL_FileFlushUnit(irawfp->rawunit); IDL_FileStat(irawfp->rawunit,&stat); ffp=stat.fptr; if (ffp==NULL) { s=-1; return (IDL_GettmpLong(s)); } if (irawfp->inxunit !=-1) { IDL_FileFlushUnit(irawfp->inxunit); IDL_FileStat(irawfp->inxunit,&stat); ifp=stat.fptr; } if (ifp !=NULL) fflush(ifp); rawfp.rawfp=fileno(ffp); if (ifp !=NULL) rawfp.inxfp=fileno(ifp); else rawfp.inxfp=-1; OldRawIDLToRawFp(irawfp,&rawfp); prm=RadarParmMake(); raw=RawMake(); s=OldRawRead(&rawfp,prm,raw); OldRawRawFpToIDL(&rawfp,irawfp); if (s==-1) { RadarParmFree(prm); RawFree(raw); return (IDL_GettmpLong(s)); } iprm=IDLMakeRadarParm(&vprm); iraw=IDLMakeRawData(&vraw); /* copy data here */ IDLCopyRadarParmToIDL(prm,iprm); IDLCopyRawDataToIDL(prm->nrang,prm->mplgs,prm->xcf,raw,iraw); RadarParmFree(prm); RawFree(raw); IDL_VarCopy(vprm,argv[1]); IDL_VarCopy(vraw,argv[2]); return (IDL_GettmpLong(s)); }
static IDL_VPTR IDLOldRawWrite(int argc,IDL_VPTR *argv) { int s=0; IDL_LONG unit=0,recnum; IDL_FILE_STAT stat; struct RadarIDLParm *iprm=NULL; struct RawIDLData *iraw=NULL; struct RadarParm *prm=NULL; struct RawData *raw=NULL; FILE *fp; IDL_ENSURE_SCALAR(argv[0]); IDL_ENSURE_STRUCTURE(argv[1]); IDL_ENSURE_STRUCTURE(argv[2]); IDL_ENSURE_SCALAR(argv[3]); IDL_EXCLUDE_EXPR(argv[1]); IDL_EXCLUDE_EXPR(argv[2]); unit=IDL_LongScalar(argv[0]); recnum=IDL_LongScalar(argv[3]); s=IDL_FileEnsureStatus(IDL_MSG_RET,unit,IDL_EFS_USER); if (s==FALSE) { s=-1; return (IDL_GettmpLong(s)); } /* Get information about the file */ IDL_FileFlushUnit(unit); IDL_FileStat(unit,&stat); /* Find the file pointer */ fp=stat.fptr; if (fp==NULL) { s=-1; return (IDL_GettmpLong(s)); } iprm=(struct RadarIDLParm *) argv[1]->value.s.arr->data; iraw=(struct RawIDLData *) argv[2]->value.s.arr->data; prm=RadarParmMake(); raw=RawMake(); IDLCopyRadarParmFromIDL(iprm,prm); IDLCopyRawDataFromIDL(prm->nrang,prm->mplgs,prm->xcf,iraw,raw); s=OldRawFwrite(fp,"rawwrite",prm,raw,recnum,NULL); RadarParmFree(prm); RawFree(raw); return (IDL_GettmpLong(s)); }