PP: Non-functional: Remove custom allocator and related improvements.
Removed the preprocesser memory pool. Removed extra copies and unnecessary allocations of objects related to the ones that were using the pool. Replaced some allocated pointers with objects instead, generally using more modern techiques. There end up being fewer memory allocations/deletions to get right. Overall combined effect of all changes is to use slightly less memory and run slightly faster (< 1% for both, but noticable). As part of simplifying the code base, this change makes it easier to see PP symbol tracking, which I suspect has an even bigger run-time simplification to make.
This commit is contained in:
parent
bfff871dad
commit
b8387c87d0
7 changed files with 97 additions and 283 deletions
|
|
@ -76,86 +76,6 @@ TORT (INCLUDING NEGLIGENCE), STRICT LIABILITY OR OTHERWISE, EVEN IF
|
|||
NVIDIA HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
\****************************************************************************/
|
||||
|
||||
#include <cstddef>
|
||||
#include <cstdlib>
|
||||
#include <cstring>
|
||||
|
||||
#include "PpContext.h"
|
||||
|
||||
// default alignment and chunksize, if called with 0 arguments
|
||||
#define CHUNKSIZE (64*1024)
|
||||
#define ALIGN 8
|
||||
|
||||
namespace glslang {
|
||||
|
||||
struct chunk {
|
||||
struct chunk *next;
|
||||
};
|
||||
|
||||
TPpContext::MemoryPool* TPpContext::mem_CreatePool(size_t chunksize, unsigned int align)
|
||||
{
|
||||
if (align == 0)
|
||||
align = ALIGN;
|
||||
if (chunksize == 0)
|
||||
chunksize = CHUNKSIZE;
|
||||
if (align & (align - 1))
|
||||
return nullptr;
|
||||
if (chunksize < sizeof(MemoryPool))
|
||||
return nullptr;
|
||||
if (chunksize & (align - 1))
|
||||
return nullptr;
|
||||
|
||||
MemoryPool *pool = (MemoryPool*)malloc(chunksize);
|
||||
if (! pool)
|
||||
return nullptr;
|
||||
|
||||
pool->next = 0;
|
||||
pool->chunksize = chunksize;
|
||||
pool->alignmask = (uintptr_t)(align) - 1;
|
||||
pool->free = ((uintptr_t)(pool + 1) + pool->alignmask) & ~pool->alignmask;
|
||||
pool->end = (uintptr_t)pool + chunksize;
|
||||
|
||||
return pool;
|
||||
}
|
||||
|
||||
void TPpContext::mem_FreePool(MemoryPool *pool)
|
||||
{
|
||||
struct chunk *p, *next;
|
||||
|
||||
for (p = (struct chunk *)pool; p; p = next) {
|
||||
next = p->next;
|
||||
free(p);
|
||||
}
|
||||
}
|
||||
|
||||
void* TPpContext::mem_Alloc(MemoryPool *pool, size_t size)
|
||||
{
|
||||
struct chunk *ch;
|
||||
void *rv = (void *)pool->free;
|
||||
size = (size + pool->alignmask) & ~pool->alignmask;
|
||||
if (size <= 0) size = pool->alignmask;
|
||||
pool->free += size;
|
||||
if (pool->free > pool->end || pool->free < (uintptr_t)rv) {
|
||||
size_t minreq = (size + sizeof(struct chunk) + pool->alignmask) & ~pool->alignmask;
|
||||
pool->free = (uintptr_t)rv;
|
||||
if (minreq >= pool->chunksize) {
|
||||
// request size is too big for the chunksize, so allocate it as
|
||||
// a single chunk of the right size
|
||||
ch = (struct chunk*)malloc(minreq);
|
||||
if (! ch)
|
||||
return nullptr;
|
||||
} else {
|
||||
ch = (struct chunk*)malloc(pool->chunksize);
|
||||
if (! ch)
|
||||
return nullptr;
|
||||
pool->free = (uintptr_t)ch + minreq;
|
||||
pool->end = (uintptr_t)ch + pool->chunksize;
|
||||
}
|
||||
ch->next = pool->next;
|
||||
pool->next = ch;
|
||||
rv = (void *)(((uintptr_t)(ch+1) + pool->alignmask) & ~pool->alignmask);
|
||||
}
|
||||
return rv;
|
||||
}
|
||||
|
||||
} // end namespace glslang
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue