/*
* This file is part of the GROMACS molecular simulation package.
*
- * Copyright (c) 2010,2011,2012,2014,2017,2018, by the GROMACS development team, led by
+ * Copyright (c) 2010,2011,2012,2014,2017,2018,2019, by the GROMACS development team, led by
* Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
* and including many others, as listed in the AUTHORS file in the
* top-level source directory and at http://www.gromacs.org.
typedef struct gmx_sel_mempool_block_t
{
//! Pointer to the start of the block (as returned to the user).
- void *ptr;
+ void* ptr;
//! Size of the block, including padding required to align next block.
- size_t size;
+ size_t size;
} gmx_sel_mempool_block_t;
/*! \internal \brief
struct gmx_sel_mempool_t
{
//! Number of bytes currently allocated from the pool.
- size_t currsize;
+ size_t currsize;
//! Number of bytes free in the pool, or 0 if \a buffer is NULL.
- size_t freesize;
+ size_t freesize;
//! Memory area allocated for the pool, or NULL if not yet reserved.
- char *buffer;
+ char* buffer;
//! Pointer to the first free byte (aligned at ::ALIGN_STEP) in \a buffer.
- char *freeptr;
+ char* freeptr;
//! Number of blocks allocated from the pool.
- int nblocks;
+ int nblocks;
//! Array describing the allocated blocks.
- gmx_sel_mempool_block_t *blockstack;
+ gmx_sel_mempool_block_t* blockstack;
//! Number of elements allocated for the \a blockstack array.
- int blockstack_nalloc;
+ int blockstack_nalloc;
/*! \brief
* Maximum number of bytes that have been reserved from the pool
* simultaneously.
*/
- size_t maxsize;
+ size_t maxsize;
};
-gmx_sel_mempool_t *
-_gmx_sel_mempool_create()
+gmx_sel_mempool_t* _gmx_sel_mempool_create()
{
- gmx_sel_mempool_t *mp;
+ gmx_sel_mempool_t* mp;
snew(mp, 1);
mp->currsize = 0;
return mp;
}
-void
-_gmx_sel_mempool_destroy(gmx_sel_mempool_t *mp)
+void _gmx_sel_mempool_destroy(gmx_sel_mempool_t* mp)
{
if (!mp->buffer)
{
- int i;
+ int i;
for (i = 0; i < mp->nblocks; ++i)
{
sfree(mp);
}
-void *
-_gmx_sel_mempool_alloc(gmx_sel_mempool_t *mp, size_t size)
+void* _gmx_sel_mempool_alloc(gmx_sel_mempool_t* mp, size_t size)
{
- void *ptr = nullptr;
- size_t size_walign;
+ void* ptr = nullptr;
+ size_t size_walign;
size_walign = ((size + ALIGN_STEP - 1) / ALIGN_STEP) * ALIGN_STEP;
if (mp->buffer)
{
GMX_THROW(gmx::InternalError("Out of memory pool memory"));
}
- ptr = mp->freeptr;
- mp->freeptr += size_walign;
+ ptr = mp->freeptr;
+ mp->freeptr += size_walign;
mp->freesize -= size_walign;
mp->currsize += size_walign;
}
return ptr;
}
-void
-_gmx_sel_mempool_free(gmx_sel_mempool_t *mp, void *ptr)
+void _gmx_sel_mempool_free(gmx_sel_mempool_t* mp, void* ptr)
{
int size;
GMX_RELEASE_ASSERT(mp->nblocks > 0 && mp->blockstack[mp->nblocks - 1].ptr == ptr,
"Invalid order of memory pool free calls");
mp->nblocks--;
- size = mp->blockstack[mp->nblocks].size;
+ size = mp->blockstack[mp->nblocks].size;
mp->currsize -= size;
if (mp->buffer)
{
- mp->freeptr = static_cast<char *>(ptr);
+ mp->freeptr = static_cast<char*>(ptr);
mp->freesize += size;
}
else
}
}
-void
-_gmx_sel_mempool_reserve(gmx_sel_mempool_t *mp, size_t size)
+void _gmx_sel_mempool_reserve(gmx_sel_mempool_t* mp, size_t size)
{
GMX_RELEASE_ASSERT(mp->nblocks == 0,
"Cannot reserve memory pool when there is something allocated");
{
size = mp->maxsize;
}
- mp->buffer = static_cast<char *>(malloc(size));
+ mp->buffer = static_cast<char*>(malloc(size));
if (!mp->buffer)
{
throw std::bad_alloc();
mp->freeptr = mp->buffer;
}
-void
-_gmx_sel_mempool_alloc_group(gmx_sel_mempool_t *mp, gmx_ana_index_t *g,
- int isize)
+void _gmx_sel_mempool_alloc_group(gmx_sel_mempool_t* mp, gmx_ana_index_t* g, int isize)
{
- void *ptr = _gmx_sel_mempool_alloc(mp, sizeof(*g->index)*isize);
- g->index = static_cast<int *>(ptr);
+ void* ptr = _gmx_sel_mempool_alloc(mp, sizeof(*g->index) * isize);
+ g->index = static_cast<int*>(ptr);
}
-void
-_gmx_sel_mempool_free_group(gmx_sel_mempool_t *mp, gmx_ana_index_t *g)
+void _gmx_sel_mempool_free_group(gmx_sel_mempool_t* mp, gmx_ana_index_t* g)
{
_gmx_sel_mempool_free(mp, g->index);
g->index = nullptr;