make vget()/vgot() inline functions again for optimal performance.

This commit is contained in:
Axel Kohlmeyer 2020-09-08 20:52:51 -04:00
parent c818a00523
commit dad749b62b
No known key found for this signature in database
GPG Key ID: D9B44E93BF0C375A
2 changed files with 36 additions and 39 deletions

View File

@ -136,43 +136,6 @@ T *MyPage<T>::get(int n) {
return &page[0];
}
/** Get pointer to location that can store *maxchunk* items.
*
* This will return the same pointer as the previous call to
* this function unless vgot() is called afterwards to record
* how many items of the chunk were actually used.
*
* \return pointer to chunk of memory or null pointer if run out of memory */
template <class T>
T *MyPage<T>::vget() {
if (index+maxchunk <= pagesize) return &page[index];
ipage++;
if (ipage == npage) {
allocate();
if (errorflag) return NULL;
}
page = pages[ipage];
index = 0;
return &page[index];
}
/** Mark *N* items as used of the chunk reserved with a preceding call to vget().
*
* This will advance the internal pointer inside the current memory page.
* It is not necessary to call this function for *N* = 0, that is the reserved
* storage was not used. A following call to vget() will then reserve the
* same location again. It is an error if *N* > *maxchunk*.
*
* \param n Number of items used in previously reserved chunk */
template <class T>
void MyPage<T>::vgot(int n) {
if (n > maxchunk) errorflag = 1;
ndatum += n;
nchunk++;
index += n;
}
/** Reset state of memory pool without freeing any memory */

View File

@ -39,8 +39,42 @@ class MyPage {
int user_pagedelta=1);
T *get(int n=1);
T *vget();
void vgot(int n);
/** Get pointer to location that can store *maxchunk* items.
*
* This will return the same pointer as the previous call to
* this function unless vgot() is called afterwards to record
* how many items of the chunk were actually used.
*
* \return pointer to chunk of memory or null pointer if run out of memory */
T *vget() {
if (index+maxchunk <= pagesize) return &page[index];
ipage++;
if (ipage == npage) {
allocate();
if (errorflag) return NULL;
}
page = pages[ipage];
index = 0;
return &page[index];
}
/** Mark *N* items as used of the chunk reserved with a preceding call to vget().
*
* This will advance the internal pointer inside the current memory page.
* It is not necessary to call this function for *N* = 0, that is the reserved
* storage was not used. A following call to vget() will then reserve the
* same location again. It is an error if *N* > *maxchunk*.
*
* \param n Number of items used in previously reserved chunk */
void vgot(int n) {
if (n > maxchunk) errorflag = 1;
ndatum += n;
nchunk++;
index += n;
}
void reset();