할당자할당자(割當子) 또는 얼로케이터(allocator)는 C++의 표준 라이브러리에서 메모리 할당을 관리하는 객체이다. C++표준 라이브러리에서 이용되는 리스트, 셋 등의 다양한 컨테이너 자료구조들은 용도에 따라 동적 메모리 할당을 요구한다. 할당자는 동적 메모리 할당을 통합 관리하는데 필요한 기능이 정의된 객체이다. 예//__gnu_cxx::new_allocator< typename > Class Template Reference
//https://gcc.gnu.org/onlinedocs/gcc-4.9.0/libstdc++/api/a00057.html
/**
processor : 0
vendor_id : AuthenticAMD
cpu family : 16
model : 6
model name : AMD Athlon(tm) II X2 270 Processor
stepping : 3
microcode : 0x10000c8
cpu MHz : 2000.000
cache size : 1024 KB
...
processor : 1
vendor_id : AuthenticAMD
cpu family : 16
model : 6
model name : AMD Athlon(tm) II X2 270 Processor
stepping : 3
microcode : 0x10000c8
cpu MHz : 800.000
cache size : 1024 KB
...
Linux debian 3.14-2-686-pae #1 SMP Debian 3.14.15-2 (2014-08-09) i686 GNU/Linux
...
gcc (Debian 4.9.1-12) 4.9.1
Copyright (C) 2014 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
...
java@debian:~/java/eclipse$ ldd /usr/lib/i386-linux-gnu/libstdc++.so.6.0.20
linux-gate.so.1 (0xb7733000)
libm.so.6 => /lib/i386-linux-gnu/i686/cmov/libm.so.6 (0xb75da000)
libc.so.6 => /lib/i386-linux-gnu/i686/cmov/libc.so.6 (0xb742f000)
/lib/ld-linux.so.2 (0xb7734000)
libgcc_s.so.1 => /lib/i386-linux-gnu/libgcc_s.so.1 (0xb7411000)
*/
#include <iostream>
using namespace std;
using namespace __gnu_cxx;
class RequiredAllocation
{
public:
RequiredAllocation ();
~RequiredAllocation ();
std::basic_string<char> s = "hello world!\n";
};
RequiredAllocation::RequiredAllocation ()
{
cout << "RequiredAllocation::RequiredAllocation()" << endl;
}
RequiredAllocation::~RequiredAllocation ()
{
cout << "RequiredAllocation::~RequiredAllocation()" << endl;
}
void alloc(__gnu_cxx ::new_allocator<RequiredAllocation>* all, unsigned int size, void* pt, RequiredAllocation* t){
try
{
all->allocate (size, pt);
cout << all->max_size () << endl;
for (auto& e : t->s)
{
cout << e;
}
}
catch (std::bad_alloc& e)
{
cout << e.what () << endl;
}
}
int
main ()
{
__gnu_cxx ::new_allocator<RequiredAllocation> *all =
new __gnu_cxx ::new_allocator<RequiredAllocation> ();
RequiredAllocation t;
void* pt = &t;
/**
* What happens when new can find no store to allocate? By default, the allocator throws a stan-
* dard-library bad_alloc exception (for an alternative, see §11.2.4.1)
* @C Bjarne Stroustrup The C++ Programming language
*/
unsigned int size = 1073741824;
alloc(all, size, &pt, &t);
size = 1;
alloc(all, size, &pt, &t);
return 0;
}
외부 링크
|
Index:
pl ar de en es fr it arz nl ja pt ceb sv uk vi war zh ru af ast az bg zh-min-nan bn be ca cs cy da et el eo eu fa gl ko hi hr id he ka la lv lt hu mk ms min no nn ce uz kk ro simple sk sl sr sh fi ta tt th tg azb tr ur zh-yue hy my ace als am an hyw ban bjn map-bms ba be-tarask bcl bpy bar bs br cv nv eml hif fo fy ga gd gu hak ha hsb io ig ilo ia ie os is jv kn ht ku ckb ky mrj lb lij li lmo mai mg ml zh-classical mr xmf mzn cdo mn nap new ne frr oc mhr or as pa pnb ps pms nds crh qu sa sah sco sq scn si sd szl su sw tl shn te bug vec vo wa wuu yi yo diq bat-smg zu lad kbd ang smn ab roa-rup frp arc gn av ay bh bi bo bxr cbk-zam co za dag ary se pdc dv dsb myv ext fur gv gag inh ki glk gan guw xal haw rw kbp pam csb kw km kv koi kg gom ks gcr lo lbe ltg lez nia ln jbo lg mt mi tw mwl mdf mnw nqo fj nah na nds-nl nrm nov om pi pag pap pfl pcd krc kaa ksh rm rue sm sat sc trv stq nso sn cu so srn kab roa-tara tet tpi to chr tum tk tyv udm ug vep fiu-vro vls wo xh zea ty ak bm ch ny ee ff got iu ik kl mad cr pih ami pwn pnt dz rmy rn sg st tn ss ti din chy ts kcg ve
Portal di Ensiklopedia Dunia