/* * MathPlanner 3.0.2 - Mathematical design tool. * Copyright(C) 2000 Jarmo Nikkanen * * This program is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License as published by the * Free Software Foundation. * * You should have received a copy of the GNU General Public License with this program. * */ #include #include #include #include "Memory.h" #include "Error.h" bool NMemory::SetSizeTo(int newsize,bool keep) { int old_s=0; int min; void *old_a=NULL; if (newsize==0) { address=NULL,size=0; return(true); } if (address && size) { old_a=address; old_s=size; } address=(void *)malloc(newsize+16); if (address==NULL) ErrorReport("Memory","Critical memory allocation error"); else { memset(address,0,newsize); if (old_ssize) return(false); return(SetSizeTo(size+inc,keep)); } bool NMemory::SetPointerTo(int pos) { if (pos>(size-1)) return(false); pointer=pos; return(true); } NMemory::NMemory(int s) { address=0; size=0; SetSizeTo(s); } NMemory::~NMemory() { if (address) free(address); size=0; address=NULL; } int NMemory::Size() { return(size); } void *NMemory::Address() { return(address); } void NMemory::Clear() { memset(address,0,size); }