设为首页 加入收藏

TOP

2011年计算机二级C++辅导实例编程(26)
2014-10-19 00:09:13 】 浏览:1783
Tags:2011年 计算机 二级 辅导 实例 编程

  使用C++ 实现缓存容量增加


  当你在某个缓存中存储数据时,常常需要在运行时调整该缓存的大小,以便能容纳更多的数据。


  下面是一个增加初始缓存大小的例子:


  view plaincopy to clipboardprint


  // console.cpp : Defines the entry point for the console application.


  //


  #include "stdafx.h"


  #include


  #include


  using namespace std;


  int reallocate(int* &p, int& size)


  {


  size*=2; // double the array''s size with each reallocation


  int * temp = new int[size];


  copy(p, p+(size/2), temp);


  delete [] p; // release original, smaller buffer


】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
上一篇2011年计算机二级C++辅导实例编程.. 下一篇2011年计算机二级C++辅导实例编程..

最新文章

热门文章

Hot 文章

Python

C 语言

C++基础

大数据基础

linux编程基础

C/C++面试题目