当前位置: 首页>>代码示例>>C++>>正文


C++ MemoryPool类代码示例

本文整理汇总了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;
}
开发者ID:Esaud17,项目名称:AmayaOS,代码行数:32,代码来源:PoolAllocator.cpp

示例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());
    }
  }
}
开发者ID:GudzonskiyYastreb,项目名称:openjdk-fontfix,代码行数:26,代码来源:memoryManager.cpp

示例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;
}
开发者ID:ArtisticCoding,项目名称:gradientdomain-mitsuba,代码行数:31,代码来源:path.cpp

示例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;
}
开发者ID:vbyeh,项目名称:ECS150-Proj3,代码行数:33,代码来源:VirtualMachine.cpp

示例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;
}
开发者ID:vbyeh,项目名称:ECS150-Proj3,代码行数:26,代码来源:VirtualMachine.cpp

示例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]);
	}
}
开发者ID:ArtisticCoding,项目名称:gradientdomain-mitsuba,代码行数:7,代码来源:path.cpp

示例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;
}
开发者ID:,项目名称:,代码行数:9,代码来源:

示例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();
}
开发者ID:,项目名称:,代码行数:10,代码来源:

示例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;
}
开发者ID:4T-Shirt,项目名称:OpenJDK-Research,代码行数:13,代码来源:lowMemoryDetector.cpp

示例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);
}
开发者ID:jasonxhill,项目名称:okavangoc,代码行数:13,代码来源:StringBufferTest.c

示例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);
  }
}
开发者ID:,项目名称:,代码行数:12,代码来源:

示例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;
            }
        }
    }
}
开发者ID:Esaud17,项目名称:AmayaOS,代码行数:13,代码来源:PoolAllocator.cpp

示例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);
}
开发者ID:jasonxhill,项目名称:okavangoc,代码行数:14,代码来源:StringBufferTest.c

示例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;
}
开发者ID:ArtisticCoding,项目名称:gradientdomain-mitsuba,代码行数:51,代码来源:path.cpp

示例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);
}
开发者ID:jasonxhill,项目名称:okavangoc,代码行数:15,代码来源:StringBufferTest.c


注:本文中的MemoryPool类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。