3 #ifndef CH_MATRIX_CLASSES__MEMARRAY_HXX 4 #define CH_MATRIX_CLASSES__MEMARRAY_HXX 17 #if (CONICBUNDLE_DEBUG>=1) 58 Entry(){next=0; addr=0; size=0;}
86 Memarray(
long number_of_entries,
int number_of_sizes,
int address_bits);
102 {
return get(size*long(
sizeof(
double)),(
char*&)
addr)/long(
sizeof(
double));}
105 {
return get(size*long(
sizeof(
float)),(
char*&)
addr)/long(
sizeof(
float));}
108 {
return get(size*long(
sizeof(
long)),(
char*&)
addr)/long(
sizeof(
long));}
111 {
return get(size*long(
sizeof(
int)),(
char*&)
addr)/long(
sizeof(
int));}
135 #if (CONICBUNDLE_DEBUG>=1) 157 if (provide<avail)
return 0;
159 long tmpavail=memarray.
get(((provide>2*avail)?provide:2*avail)*
long(
sizeof(T)),(
char *&)tmpstore)/long(
sizeof(T));
160 if ((tmpstore==0)&&(provide<2*avail)){
161 tmpavail=memarray.
get(provide*
long(
sizeof(T)),(
char *&)tmpstore)/long(
sizeof(T));
163 if (tmpstore==0)
return 1;
166 tmpstore[i]=store[i];
168 memarray.
free((
void *)store);
183 if (provide<avail)
return 0;
185 long tmpavail=memarray.
get(((provide>2*avail)?provide:2*avail)*
long(
sizeof(T)),(
char *&)tmpstore)/long(
sizeof(T));
186 if ((tmpstore==0)&&(provide<2*avail)){
187 tmpavail=memarray.
get(provide*
long(
sizeof(T)),(
char *&)tmpstore)/long(
sizeof(T));
189 if (tmpstore==0)
return 1;
191 for(i=0;i<avail;i++){
192 tmpstore[i]=store[i];
194 for(;i<tmpavail;i++){
197 memarray.
free((
void *)store);
holds the information of one allocated block and serves as an item in the singly linked lists ...
Definition: memarray.hxx:50
error arises in a global function
Definition: matop.hxx:1586
long index_size(int index)
compute size of blocks in the free list with this index
int size_index(long size)
compute index for free list to a request of size
int mem_provide(Memarray &memarray, long provide, long in_use, long &avail, T *&store)
provide sufficient memory for an existing array, reallocating and copying the old information upon ne...
Definition: memarray.hxx:149
A simple memory manager for frequent allocation and deallocation of arrays of roughly the same size...
Definition: memarray.hxx:46
Entry first_empty
its next pointer points to the first free CH_Matrix_Classes::Memarray::Entry item, that does not yet hold an allocated block
Definition: memarray.hxx:70
int get_more_entries()
double number of available CH_Matrix_Classes::Memarray::Entry items
unsigned long increment_memarray_users()
announce a new user
Definition: memarray.hxx:94
long size
gives the size of the allocated block
Definition: memarray.hxx:54
static Memarray * memarray
pointer to common memory manager for all Memarrayusers, instantiated in memarray.cxx ...
Definition: memarray.hxx:121
unsigned long memarray_users
number of objects announced as "living" users of this memory manager
Definition: memarray.hxx:68
Entry * entry_store
points to the allocated array of CH_Matrix_Classes::Memarray::Entry items
Definition: memarray.hxx:71
Such an object is generated and passed to MEmessage(), whenever an error occurs. It holds some output...
Definition: matop.hxx:1609
Entry * next
points to the next entry in the list
Definition: memarray.hxx:52
int MEmessage(const MatrixError &)
displays an error message and terminates via abort() or returns 1 in case of warnings.
int free(void *addr)
free the array pointed to by addr (addr must be an address returned by get)
Entry * first_free
points to an array of size max_sizes, its Entry i start the free list for size 2^i ...
Definition: memarray.hxx:72
char * addr
points to the allocated block
Definition: memarray.hxx:53
long max_sizes
current number of lists holding free blocks
Definition: memarray.hxx:64
unsigned long in_use
number of CH_Matrix_Classes::Memarray::Entry items in use (pointing to an allocated block) ...
Definition: memarray.hxx:67
unsigned long get_in_use() const
returns the number of CH_Matrix_Classes::Memarray::Entry items in use
Definition: memarray.hxx:90
Basic types, constants and templates for simple linear algebra routines like BLAS level 1...
Matrix Classes and Linear Algebra. See Matrix Classes (namespace CH_Matrix_Classes) for a quick intro...
Definition: PSCOracle.hxx:20
int addr_index(const char *addr)
compute index into address class to retrieve entry of "addr"
int index
gives the index of the size group of this block
Definition: memarray.hxx:55
long get(long size, char *&addr)
request a character array of at least this size, the address is then stored in addr and the actual si...
unsigned long decrement_memarray_users()
decrement number of announced users
Definition: memarray.hxx:96
unspecified error type, not in the list below
Definition: matop.hxx:1600
Memarray(long number_of_entries, int number_of_sizes, int address_bits)
specify inital number of Entry items, the number of 2^i classes, the number of last bits used in find...
All derived classes share a common Memarray memory manager, which is generated with the first user an...
Definition: memarray.hxx:117
long max_entries
current number of CH_Matrix_Classes::Memarray::Entry items available
Definition: memarray.hxx:63
Memarrayuser()
if memarray is NULL, then a new Memarray is generated. In any case the number of users of the Memarra...
Definition: memarray.hxx:124
virtual ~Memarrayuser()
the number of users is decremented and the Memarray memory manager is destructed, if the number is ze...
Definition: memarray.hxx:133
Entry * first_used
points to an array of size max_addr_entr, its Entry i start the list of entries whose memory is in us...
Definition: memarray.hxx:73
unsigned long get_memarray_users() const
returns the number of announced "living" users of this Memory manager
Definition: memarray.hxx:92
long max_addr_entr
current number of lists hodling occupied blocks
Definition: memarray.hxx:65
int mem_provide_init0(Memarray &memarray, long provide, long &avail, T *&store)
provide sufficient memory for an existing array, reallocating and copying the old information and ini...
Definition: memarray.hxx:176
unsigned long addr_mask
mask to extract last bits of an address as index for freeing
Definition: memarray.hxx:66