1234567891011121314151617181920212223242526272829303132333435 |
- #ifndef NANXING_NEW_H_
- #define NANXING_NEW_H_ 1
- #include<iostream>
- namespace nanxing{
-
-
- void* safe_new(size_t size)
- {
- char* data=(char*)malloc(size+1);
- *data='{';
- data+=1;
- return static_cast<void*>(data);
- }
- void safe_delete(void* data,size_t)
- {
- char * middle=static_cast<char*>(data);
- middle-=1;
- if(*middle=='{')
- {
- *middle='\n';
- free(static_cast<void*>(middle));
- }
- else{
- std::cerr<<"The space has not been free"<<std::endl;
- }
- }
- }
- #endif
|