update/correct documentation for memory pool classes

This commit is contained in:
Axel Kohlmeyer
2020-09-08 16:36:48 -04:00
parent 9f4a991fc5
commit ee25ed3897
2 changed files with 23 additions and 9 deletions

View File

@ -73,10 +73,10 @@ MyPage<T>::~MyPage() {
* This also frees all previously allocated storage and allocates * This also frees all previously allocated storage and allocates
* the first page(s). * the first page(s).
* *
* \param user_maxchunk Expected maximum number of items for one chunk * \param user_maxchunk Expected maximum number of items for one chunk
* \param user_pagesize Number of items on a single memory page * \param user_pagesize Number of items on a single memory page
* \param user_page_delta Number of pages to allocate with one malloc * \param user_pagedelta Number of pages to allocate with one malloc
* \return 1 if there was an error or 0 if successful */ * \return 1 if there were invalid parameters, 2 if there was an allocation error or 0 if successful */
template<class T> template<class T>
int MyPage<T>::init(int user_maxchunk, int user_pagesize, int MyPage<T>::init(int user_maxchunk, int user_pagesize,

View File

@ -40,7 +40,14 @@ using namespace LAMMPS_NS;
* to be added at the end of the file ``src/my_pool_chunk.cpp`` to * to be added at the end of the file ``src/my_pool_chunk.cpp`` to
* avoid symbol lookup errors. */ * avoid symbol lookup errors. */
/** Create a class instance and set memory pool parameters */ /** Create a class instance and set memory pool parameters
*
* \param user_minchunk Minimal chunk size
* \param user_maxchunk Maximal chunk size
* \param user_nbin Number of bins of different chunk sizes
* \param user_chunkperpage Number of chunks per page
* \param user_pagedelta Numner of pages to allocate in one go */
template <class T> template <class T>
MyPoolChunk<T>::MyPoolChunk(int user_minchunk, int user_maxchunk, int user_nbin, MyPoolChunk<T>::MyPoolChunk(int user_minchunk, int user_maxchunk, int user_nbin,
int user_chunkperpage, int user_pagedelta) { int user_chunkperpage, int user_pagedelta) {
@ -100,7 +107,10 @@ T *MyPoolChunk<T>::get(int &index) {
int ibin = nbin-1; int ibin = nbin-1;
if (freehead[ibin] < 0) { if (freehead[ibin] < 0) {
allocate(ibin); allocate(ibin);
if (errorflag) return nullptr; if (errorflag) {
index = -1;
return nullptr;
}
} }
ndatum += maxchunk; ndatum += maxchunk;
@ -122,13 +132,17 @@ template <class T>
T *MyPoolChunk<T>::get(int n, int &index) { T *MyPoolChunk<T>::get(int n, int &index) {
if (n < minchunk || n > maxchunk) { if (n < minchunk || n > maxchunk) {
errorflag = 3; errorflag = 3;
index = -1
return nullptr; return nullptr;
} }
int ibin = (n-minchunk) / binsize; int ibin = (n-minchunk) / binsize;
if (freehead[ibin] < 0) { if (freehead[ibin] < 0) {
allocate(ibin); allocate(ibin);
if (errorflag) return nullptr; if (errorflag) {
index = -1;
return nullptr;
}
} }
ndatum += n; ndatum += n;
@ -141,8 +155,8 @@ T *MyPoolChunk<T>::get(int n, int &index) {
} }
/** Put indexed chunk back into memory pool via free list /** Put indexed chunk back into memory pool via free list
*/ *
// index = -1 if no allocated chunk * \param index Memory chunk index returned by call to get() */
template <class T> template <class T>
void MyPoolChunk<T>::put(int index) { void MyPoolChunk<T>::put(int index) {