資源簡(jiǎn)介
C++內(nèi)存管理課件和代碼侯捷老師的ppt,C++內(nèi)存管理課件和代碼侯捷老師C++內(nèi)存管理課件和代碼侯捷老師
代碼片段和文件信息
//?author?:?Hou?Jie?(侯捷)
//?date?:?2015/11/11?
//?compiler?:?DevC++?5.61?(MinGW?with?GNU?4.9.2)
//
//?說(shuō)明:這是侯捷?E-learning?video?“C++內(nèi)存管理“?的實(shí)例程式.
//?該課程的所有測(cè)試都出現(xiàn)在此.
//?每一個(gè)小測(cè)試單元都被放進(jìn)一個(gè)?namespace?中?
//?如此保持各單元間最大的獨(dú)立性.
//?每個(gè)?namespace?上方皆有該單元相應(yīng)的?#include?<...>?
//?因此有可能整個(gè)程式重複含入?(included)?某些?headers??
//?這無(wú)所謂,因?yàn)槊總€(gè)?standard?headers?都有自我防衛(wèi)機(jī)制,不讓自己被?included?二次.
//
//?本文件用到若干?GNU?C++?extended?allocators,所以你或許需要在你的集成環(huán)境?(IDE)?上設(shè)定?“C++11?on“.?
//?我已將相關(guān)代碼包裝在?編譯條件選項(xiàng)?__GNUC__?中。?
/*
#include?
#include?
#include??
#include??//strlen()
#include?
#include?
*/
using?namespace?std;
//----------------------------------------------------
#include?
#include?
#include? ?//std::allocator??
#include? ?//欲使用?std::allocator?以外的?allocator?就得自行?#include??
namespace?jj01
{
void?test_primitives()
{
cout?<“\ntest_primitives()..........?\n“;
????void*?p1?=?malloc(512); //512?bytes
????free(p1);
????complex*?p2?=?new?complex;?//one?object
????delete?p2;?????????????
????void*?p3?=?::operator?new(512);?//512?bytes
????::operator?delete(p3);
//以下使用?C++?標(biāo)準(zhǔn)庫(kù)提供的?allocators。
//其接口雖有標(biāo)準(zhǔn)規(guī)格,但實(shí)現(xiàn)廠商並未完全遵守;下面三者形式略異。
#ifdef?_MSC_VER
????//以下兩函數(shù)都是?non-static,定要通過(guò)?object?調(diào)用。以下分配?3?個(gè)?ints.
????int*?p4?=?allocator().allocate(3?(int*)0);?
????allocator().deallocate(p43);???????????
#endif
#ifdef?__BORLANDC__
????//以下兩函數(shù)都是?non-static,定要通過(guò)?object?調(diào)用。以下分配?5?個(gè)?ints.
????int*?p4?=?allocator().allocate(5);??
????allocator().deallocate(p45);???????
#endif
#ifdef?__GNUC__
????//以下兩函數(shù)都是?static,可通過(guò)全名調(diào)用之。以下分配?512?bytes.
????//void*?p4?=?alloc::allocate(512);?
????//alloc::deallocate(p4512);???
????
????//以下兩函數(shù)都是?non-static,定要通過(guò)?object?調(diào)用。以下分配?7?個(gè)?ints.????
void*?p4?=?allocator().allocate(7);?
????allocator().deallocate((int*)p47);?????
????//以下兩函數(shù)都是?non-static,定要通過(guò)?object?調(diào)用。以下分配?9?個(gè)?ints.
void*?p5?=?__gnu_cxx::__pool_alloc().allocate(9);?
????__gnu_cxx::__pool_alloc().deallocate((int*)p59);
#endif
}
}?//namespace
//----------------------------------------------------
#include?
#include?
//#include? ?//std::allocator??
namespace?jj02
{
class?A
{
public:
??int?id;
??
??A()?:?id(0)??????{?cout?<“default?ctor.?this=“??<??A(int?i)?:?id(i)?{?cout?<“ctor.?this=“??<??~A()?????????????{?cout?<“dtor.?this=“??<};
void?test_call_ctor_directly()
{
cout?<“\ntest_call_ctor_directly()..........?\n“;
????string*?pstr?=?new?string;
????cout?<“str=?“?<*pstr?<????
//!?pstr->string::string(“jjhou“);??
????????????????????????//[Error]?‘class?std::basic_string‘?has?no?member?named?‘string‘
//!?pstr->~string(); //crash?--?其語(yǔ)法語(yǔ)意都是正確的?crash?只因?yàn)樯弦恍斜?remark?起來(lái)嘛.??
????cout?<“str=?
?屬性????????????大小?????日期????時(shí)間???名稱
-----------?---------??----------?-----??----
?????文件???????96268??2015-11-17?19:23??C++內(nèi)存管理課件和代碼侯捷老師\C++內(nèi)存管理示例.cpp
?????文件?????1647346??2015-11-17?19:23??C++內(nèi)存管理課件和代碼侯捷老師\C++內(nèi)存管理示例.exe
?????文件??????184322??2015-12-23?17:20??C++內(nèi)存管理課件和代碼侯捷老師\C++內(nèi)存管理簡(jiǎn)介-侯捷.pdf
?????文件???????15850??2015-11-17?19:23??C++內(nèi)存管理課件和代碼侯捷老師\allocc.h
?????文件????36386090??2015-12-23?15:45??C++內(nèi)存管理課件和代碼侯捷老師\內(nèi)存管理.pdf
?????文件?????7959780??2015-12-23?17:40??C++內(nèi)存管理課件和代碼侯捷老師\內(nèi)存管理第五講.pdf
?????文件???????????0??2018-05-25?16:20??C++內(nèi)存管理課件和代碼侯捷老師\感謝大家下載.txt
?????目錄???????????0??2018-05-25?16:20??C++內(nèi)存管理課件和代碼侯捷老師\
評(píng)論
共有 條評(píng)論