本文整理汇总了C++中MemoryPool类的典型用法代码示例。如果您正苦于以下问题:C++ MemoryPool类的具体用法?C++ MemoryPool怎么用?C++ MemoryPool使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了MemoryPool类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: allocate
Address PoolAllocator::allocate(Size *size)
{
Size index, nPools = 1;
MemoryPool *pool = ZERO;
/* Find the correct pool size. */
for (index = POOL_MIN_POWER; index < POOL_MAX_POWER; index++)
if (*size <= (Size) 1 << (index + 1)) break;
/* Do we need to allocate an initial pool? */
if (!pools[index] && parent)
pool = pools[index] = newPool(index, POOL_MIN_COUNT(*size));
/* Search for pool with enough memory. */
else {
/* Loop current pools. */
for (pool = pools[index]; pool; pool = pool->next, nPools++) {
/* At least one block still free? */
if (pool->free)
break;
/* If no pool has free space anymore, allocate another. */
if (!pool->next) {
pool = newPool(index, POOL_MIN_COUNT(*size) * nPools);
break;
}
}
}
/* Attempt to allocate. */
return pool ? pool->allocate() : ZERO;
}
示例2: assert
void GCMemoryManager::gc_begin(bool recordGCBeginTime, bool recordPreGCUsage,
bool recordAccumulatedGCTime) {
assert(_last_gc_stat != NULL && _current_gc_stat != NULL, "Just checking");
if (recordAccumulatedGCTime) {
_accumulated_timer.start();
}
// _num_collections now increases in gc_end, to count completed collections
if (recordGCBeginTime) {
_current_gc_stat->set_index(_num_collections+1);
_current_gc_stat->set_start_time(Management::timestamp());
}
if (recordPreGCUsage) {
// Keep memory usage of all memory pools
for (int i = 0; i < MemoryService::num_memory_pools(); i++) {
MemoryPool* pool = MemoryService::get_memory_pool(i);
MemoryUsage usage = pool->get_memory_usage();
_current_gc_stat->set_before_gc_usage(i, usage);
HS_DTRACE_PROBE8(hotspot, mem__pool__gc__begin,
name(), strlen(name()),
pool->name(), strlen(pool->name()),
usage.init_size(), usage.used(),
usage.committed(), usage.max_size());
}
}
}
示例3: randomWalk
int Path::randomWalk(const Scene *scene, Sampler *sampler,
int nSteps, int rrStart, ETransportMode mode,
MemoryPool &pool) {
/* Determine the relevant edge and vertex to start the random walk */
PathVertex *curVertex = m_vertices[m_vertices.size()-1],
*predVertex = m_vertices.size() < 2 ? NULL :
m_vertices[m_vertices.size()-2];
PathEdge *predEdge = m_edges.empty() ? NULL :
m_edges[m_edges.size()-1];
Spectrum throughput(1.0f);
for (int i=0; i<nSteps || nSteps == -1; ++i) {
PathVertex *succVertex = pool.allocVertex();
PathEdge *succEdge = pool.allocEdge();
if (!curVertex->sampleNext(scene, sampler, predVertex, predEdge, succEdge,
succVertex, mode, rrStart != -1 && i >= rrStart, &throughput)) {
pool.release(succVertex);
pool.release(succEdge);
return i;
}
append(succEdge, succVertex);
predVertex = curVertex;
curVertex = succVertex;
predEdge = succEdge;
}
return nSteps;
}
示例4: VMMemoryPoolAllocate
TVMStatus VMMemoryPoolAllocate(TVMMemoryPoolID memory, TVMMemorySize size, void **pointer){
TMachineSignalState sigState;
MachineSuspendSignals(&sigState);
ThreadStore* tStore = ThreadStore::getInstance();
if((size == 0) || (pointer == NULL)){
printf("VMMemoryPoolAllocate(): size was zero or pointer was null.\n");
MachineResumeSignals(&sigState);
return VM_STATUS_ERROR_INVALID_PARAMETER;
}
// printf("VMMemoryPoolAllocate(): looking for pool: %d\n", memory);
MemoryPool *pool = tStore->findMemoryPoolByID(memory);
if(pool == NULL){
printf("VMMemoryPoolAllocate(): pool was null.\n");
MachineResumeSignals(&sigState);
return VM_STATUS_ERROR_INVALID_PARAMETER;
}
uint8_t* newMemory = pool->allocateMemory(size);
// printf("VMMemoryPoolAllocate(): allocated chunk %d\n", newMemory);
if(newMemory == NULL){
printf("VMMemoryPoolAllocate(): new memory allocated was null.\n");
return VM_STATUS_ERROR_INSUFFICIENT_RESOURCES;
}
// printf("VMMemoryPoolAllocate(): Memory allocated successfully!\n");
*pointer = newMemory; //if execution gets here, everything is valid and
MachineResumeSignals(&sigState); //the memory should be allocated
return VM_STATUS_SUCCESS;
}
示例5: VMMemoryPoolDeallocate
TVMStatus VMMemoryPoolDeallocate(TVMMemoryPoolID memory, void *pointer){
TMachineSignalState sigState;
MachineSuspendSignals(&sigState);
ThreadStore* tStore = ThreadStore::getInstance();
if(pointer == NULL){
printf("VMMemoryPoolDeallocate(): pointer was null.\n");
return VM_STATUS_ERROR_INVALID_PARAMETER;
}
MemoryPool *pool = tStore->findMemoryPoolByID(memory);
if(pool == NULL){
printf("VMMemoryPoolDeallocate(): pool was null.\n");
return VM_STATUS_ERROR_INVALID_PARAMETER;
}
// printf("VMMemoryPoolDeallocate(): attempting to deallocate chunk %d\n", pointer);
if(pool->deallocate((uint8_t*)pointer) == false){ //attempts to deallocate the memory specified by pointer
return VM_STATUS_ERROR_INVALID_PARAMETER; //returns true on successful deallocation, and false if the
}//memory pointed to by pointer was not previously allocated in the memory pool
MachineResumeSignals(&sigState);
return VM_STATUS_SUCCESS;
}
示例6: release
void Path::release(size_t start, size_t end, MemoryPool &pool) {
for (size_t i=start; i<end; ++i) {
pool.release(m_vertices[i]);
if (i+1 < end)
pool.release(m_edges[i]);
}
}
示例7: get_memory_pool
MemoryPool* MemoryService::get_memory_pool(instanceHandle ph) {
for (int i = 0; i < _pools_list->length(); i++) {
MemoryPool* pool = _pools_list->at(i);
if (pool->is_pool(ph)) {
return pool;
}
}
return NULL;
}
示例8: track_memory_usage
void MemoryService::track_memory_usage() {
// Track the peak memory usage
for (int i = 0; i < _pools_list->length(); i++) {
MemoryPool* pool = _pools_list->at(i);
pool->record_peak_memory_usage();
}
// Detect low memory
LowMemoryDetector::detect_low_memory();
}
示例9: recompute_enabled_for_collected_pools
// recompute enabled flag
void LowMemoryDetector::recompute_enabled_for_collected_pools() {
bool enabled = false;
int num_memory_pools = MemoryService::num_memory_pools();
for (int i=0; i<num_memory_pools; i++) {
MemoryPool* pool = MemoryService::get_memory_pool(i);
if (pool->is_collected_pool() && is_enabled(pool)) {
enabled = true;
break;
}
}
_enabled_for_collected_pools = enabled;
}
示例10: testAppendChar
//-----------------------------------------------------------------------------
static void testAppendChar()
{
MemoryPool pool = newMemoryPool();
StringBuffer s = newStringBuffer(&pool, "A test string");
s.appendChar(&s, '!');
assertEquals(string, "A test string!", s.str);
s.appendChar(&s, '-');
assertEquals(string, "A test string!-", s.str);
pool.drain(&pool);
}
示例11: oops_do
void MemoryService::oops_do(OopClosure* f) {
int i;
for (i = 0; i < _pools_list->length(); i++) {
MemoryPool* pool = _pools_list->at(i);
pool->oops_do(f);
}
for (i = 0; i < _managers_list->length(); i++) {
MemoryManager* mgr = _managers_list->at(i);
mgr->oops_do(f);
}
}
示例12: release
void PoolAllocator::release(Address addr)
{
for (Size i = POOL_MIN_POWER - 1; i < POOL_MAX_POWER; i++) {
for (MemoryPool *p = pools[i]; p; p = p->next) {
if (addr < p->addr + (p->count * p->size) &&
addr >= p->addr)
{
p->release(addr);
return;
}
}
}
}
示例13: testAppendString
//-----------------------------------------------------------------------------
static void testAppendString()
{
MemoryPool pool = newMemoryPool();
StringBuffer s = newStringBuffer(&pool, "A test string");
s.append(&s, " - appended value");
assertEquals(string, "A test string - appended value", s.str);
s.append(&s, " & another value");
assertEquals(string, "A test string - appended value & another value", s.str);
assertTrue(s.size > strlen("A test string - appended value & another value"));
pool.drain(&pool);
}
示例14: randomWalkFromPixel
int Path::randomWalkFromPixel(const Scene *scene, Sampler *sampler,
int nSteps, const Point2i &pixelPosition, int rrStart, MemoryPool &pool) {
PathVertex *v1 = pool.allocVertex(), *v2 = pool.allocVertex();
PathEdge *e0 = pool.allocEdge(), *e1 = pool.allocEdge();
/* Use a special sampling routine for the first two sensor vertices so that
the resulting subpath passes through the specified pixel position */
int t = vertex(0)->sampleSensor(scene,
sampler, pixelPosition, e0, v1, e1, v2);
if (t < 1) {
pool.release(e0);
pool.release(v1);
return 0;
}
append(e0, v1);
if (t < 2) {
pool.release(e1);
pool.release(v2);
return 1;
}
append(e1, v2);
PathVertex *predVertex = v1, *curVertex = v2;
PathEdge *predEdge = e1;
Spectrum throughput(1.0f);
for (; t<nSteps || nSteps == -1; ++t) {
PathVertex *succVertex = pool.allocVertex();
PathEdge *succEdge = pool.allocEdge();
if (!curVertex->sampleNext(scene, sampler, predVertex, predEdge, succEdge,
succVertex, ERadiance, rrStart != -1 && t >= rrStart, &throughput)) {
pool.release(succVertex);
pool.release(succEdge);
return t;
}
append(succEdge, succVertex);
predVertex = curVertex;
curVertex = succVertex;
predEdge = succEdge;
}
return nSteps;
}
示例15: testToString
//-----------------------------------------------------------------------------
static void testToString()
{
MemoryPool pool = newMemoryPool();
StringBuffer sb = newStringBuffer(&pool, "A test strin");
sb.appendChar(&sb, 'g');
assertEquals(string, "A test string", sb.str);
string s = sb.toString(&sb, &pool);
assertEquals(string, "A test string", s);
assertEquals(unsigned_int, 13, strlen(s));
pool.drain(&pool);
}