1 /** Aesalon, a tool to visualize program behaviour in real time.
2 Copyright (C) 2009-2011, Aesalon development team.
4 Aesalon is distributed under the terms of the GNU GPLv3. See
5 the included file LICENSE for more information.
7 @file src/storage/Mempool.cpp
14 #include "storage/Mempool.h"
15 #include "util/MessageSystem.h"
27 void *Mempool::request(uint32_t size
) {
28 int pools
= m_mapVector
.size();
30 for(pool
= 0; pool
< pools
; pool
++) {
31 if(m_useVector
[pool
] + size
<= m_mempoolSize
) break;
34 if(pool
== pools
) createNew();
36 m_useVector
[pool
] += size
;
38 return (m_mapVector
[pool
] + m_useVector
[pool
] - size
);
41 void Mempool::createNew() {
42 void *memory
= mmap(NULL
, m_mempoolSize
, PROT_READ
| PROT_WRITE
, MAP_PRIVATE
| MAP_ANONYMOUS
, 0, 0);
43 if(memory
== MAP_FAILED
) {
44 Message(Fatal
, "Could not create memory mapping: " << std::strerror(errno
));
46 m_mapVector
.push_back(static_cast<uint8_t *>(memory
));
47 m_useVector
.push_back(0);
50 } // namespace Storage