/********************************************************************
created: 2014/03/17 18:53
filename: main.cpp
author: Justme0 (http://blog.csdn.net/justme0) purpose: code project 内存管理
*********************************************************************/
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <new>
using namespace std; // Overload the new operator
void *operator new ( size_t size , bool isAllocFailure )
{
if ( isAllocFailure )
return NULL;
else
{
try
{
void *Memory = ::operator new ( size );
return Memory;
}
catch ( std::bad_alloc )
{
return NULL;
}
}
return NULL;
} // Overload placement delete operator so that exceptions from
// constructors can be handled
void operator delete ( void * Memory , bool isAllocFailure )
{
::delete Memory;
} void SimpleFunction ( int MemCounter , bool AllFail )
{ int LocalCounter = ;
char *Mem1 = new ( ( MemCounter == LocalCounter ++ ) || AllFail ) char [ ];
if ( Mem1 != NULL )
strcpy ( Mem1 , "First Memory" ); char *Mem2 = new ( ( MemCounter == LocalCounter ++ ) || AllFail ) char [ ];
if ( Mem2 != NULL )
strcpy ( Mem2 , "Second Memory" ); int NumTimesLoop = ;
int LoopCounter = ; // Create a Variable that will be allocate Inner Memory
char **InnerMemory = new ( ( MemCounter == LocalCounter ++ ) || AllFail ) char * [ NumTimesLoop ]; // Loop through and allocate the memory required
for ( LoopCounter = ; LoopCounter < NumTimesLoop ; LoopCounter ++ )
{
InnerMemory [ LoopCounter ] = new ( ( MemCounter == LocalCounter ++ ) || AllFail ) char [ ];
} } int main()
{
for ( int counter = ; counter < ; counter ++ )
SimpleFunction ( counter , false );
SimpleFunction ( - , true ); return ;
}

code project 上的内存管理的示例代码的更多相关文章

  1. vue mpvue 上拉加载更多示例代码

    vue 上拉加载更多示例代码 可以比较简单的改为 mpvue , 去除滚动判断,直接放在 onReachBottom 周期即可. html <div id="app"> ...

  2. TaskTracker节点上的内存管理器

    Hadoop平台的最大优势就是充分地利用了廉价的PC机,这也就使得集群中的工作节点存在一个重要的问题——节点所在的PC机内存资源有限(这里所说的工作节点指的是TaskTracker节点),执行任务时常 ...

  3. linux内存管理--slab及其代码解析

    Linux内核使用了源自于 Solaris 的一种方法,但是这种方法在嵌入式系统中已经使用了很长时间了,它是将内存作为对象按照大小进行分配,被称为slab高速缓存. 内存管理的目标是提供一种方法,为实 ...

  4. SkylineGlobe 6.6 三维地图上实现自定义右键菜单示例代码

    1.OnRButtonDown.htm <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" &quo ...

  5. 《深入理解Android虚拟机内存管理》示例程序编译阶段生成的各种语法树完整版

    1.tokens "int"                   "int" <SPACES>                " &quo ...

  6. JNI中的内存管理(转)

    源:JNI中的内存管理 JNI 编程简介 JNI,Java Native Interface,是 native code 的编程接口.JNI 使 Java 代码程序可以与 native code 交互 ...

  7. 一文带你彻底了解大数据处理引擎Flink内存管理

    摘要: Flink是jvm之上的大数据处理引擎. Flink是jvm之上的大数据处理引擎,jvm存在java对象存储密度低.full gc时消耗性能,gc存在stw的问题,同时omm时会影响稳定性.同 ...

  8. JavaScript的内存管理

    JavaScript的内存管理 1.什么是内存管理? 在了解JavaScript的内存管理之前,可以先大致熟悉一下什么是内存管理,不管什么样的编程语言,在其代码执行的过程中都是需要为其分配内存的. 不 ...

  9. 【C# .Net GC】自动内存管理

    原文:https://docs.microsoft.com/zh-cn/dotnet/standard/automatic-memory-management 自动内存管理是公共语言运行时在托管执行过 ...

随机推荐

  1. Struts2中使用OGNL

    链接:Struts标签库 OGNL(Object Graphic Navigatino Language) OGNL称为对象图导航语言.以一个对象为根(起点),通过OGNL可以访问与这个对象关联的其它 ...

  2. 浅谈oracle10G spfile与pfile(转)

    转自:http://blog.csdn.net/onebigday/article/details/6108348,http://www.linuxidc.com/Linux/2012-11/7371 ...

  3. python3+ 模块学习 之 re

    re 模块 参考:Python3 如何优雅地使用正则表达式(详解系列) Python3 正则表达式特殊符号及用法(详细列表)    (出处: 鱼C论坛) 正则表达式 常用元字符:. ^ $ * + ? ...

  4. Chrome Dev Tools :成为更高效的开发人员

    原文出处 http://blog.jobbole.com/22065/ 实时CSS Style编辑 选择一个Dom,可以对Dom进行编辑和操作,实时修改Css Style, 同时CssStyle可以保 ...

  5. nginx缓存设置proxy_cache

    http://www.cnblogs.com/dudu/p/4597351.html http块: proxy_cache_path /tmp/cache levels=1:2 keys_zone=n ...

  6. How to acquire an Android phone with locked bootloader?

    As we know that some devices come with locked bootloaders like Sony, HUAWEI, hTC...If you try to unl ...

  7. 用JS实现九九乘法表

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  8. 27. Oracle 10g下emctl start dbconsole 报错:OC4J Configuration issue 问题解决

    (dbconsole配置好外面的sqlplus才能连的上服务器上的数据库) 采取重新配置emctl 的方法来解决 [oracle@guohuias3 oracle]$ emca -config dbc ...

  9. linux top命令中各cpu占用率含义

    linux top命令中各cpu占用率含义 [尊重原创文章摘自:http://www.iteye.com/topic/1137848]0.3% us 用户空间占用CPU百分比 1.0% sy 内核空间 ...

  10. 解决zookeeper报错[NIOServerCxn.Factory:0.0.0.0/0.0.0.0:2181:NIOServerCnxn@362] - Exception causing close

    zookeeper.out报错: 2016-12-10 18:05:46,958 [myid:3] - WARN  [NIOServerCxn.Factory:0.0.0.0/0.0.0.0:2181 ...