allocators.hpp limits /usr/include/gecode/kernel.hh Gecode::space_allocator Gecode::space_allocator< void > Gecode::space_allocator< void >::rebind Gecode::space_allocator Gecode::space_allocator::rebind Gecode::region_allocator Gecode::region_allocator< void > Gecode::region_allocator< void >::rebind Gecode::region_allocator Gecode::region_allocator::rebind Gecode /*-*-mode:C++;c-basic-offset:2;indent-tabs-mode:nil-*-*/ /* *Mainauthors: *FilipKonvicka<filip.konvicka@logis.cz> * *Copyright: *LOGIS,s.r.o.,2009 * *Bugfixesprovidedby: *GustavoGutierrez * *Lastmodified: *$Date:2013-03-0717:39:13+0100(Thu,07Mar2013)$by$Author:schulte$ *$Revision:13458$ * *Permissionisherebygranted,freeofcharge,toanypersonobtaining *acopyofthissoftwareandassociateddocumentationfiles(the *"Software"),todealintheSoftwarewithoutrestriction,including *withoutlimitationtherightstouse,copy,modify,merge,publish, *distribute,sublicense,and/orsellcopiesoftheSoftware,andto *permitpersonstowhomtheSoftwareisfurnishedtodoso,subjectto *thefollowingconditions: * *Theabovecopyrightnoticeandthispermissionnoticeshallbe *includedinallcopiesorsubstantialportionsoftheSoftware. * *THESOFTWAREISPROVIDED"ASIS",WITHOUTWARRANTYOFANYKIND, *EXPRESSORIMPLIED,INCLUDINGBUTNOTLIMITEDTOTHEWARRANTIESOF *MERCHANTABILITY,FITNESSFORAPARTICULARPURPOSEAND *NONINFRINGEMENT.INNOEVENTSHALLTHEAUTHORSORCOPYRIGHTHOLDERSBE *LIABLEFORANYCLAIM,DAMAGESOROTHERLIABILITY,WHETHERINANACTION *OFCONTRACT,TORTOROTHERWISE,ARISINGFROM,OUTOFORINCONNECTION *WITHTHESOFTWAREORTHEUSEOROTHERDEALINGSINTHESOFTWARE. */ #include<limits> namespaceGecode{ template<classT>structspace_allocator; template<> structspace_allocator<void>{ typedefvoid*pointer; typedefconstvoid*const_pointer; typedefvoidvalue_type; template<classU>structrebind{ typedefspace_allocator<U>other; }; }; template<classT> structspace_allocator{ typedefTvalue_type; typedefsize_tsize_type; typedefptrdiff_tdifference_type; typedefT*pointer; typedefTconst*const_pointer; typedefT&reference; typedefTconst&const_reference; template<classU>structrebind{ typedefspace_allocator<U>other; }; Space&space; space_allocator(Space&space)throw():space(space){} space_allocator(space_allocatorconst&al)throw():space(al.space){} space_allocator&operator =(space_allocatorconst&al){ (void)al; assert(&space==&al.space); return*this; } template<classU> space_allocator(space_allocator<U>const&al)throw():space(al.space){} pointeraddress(referencex)const{return&x;} const_pointeraddress(const_referencex)const{return&x;} size_typemax_size(void)constthrow(){ returnstd::numeric_limits<size_type>::max()/ (sizeof(T)>0?sizeof(T):1); } pointerallocate(size_typecount){ returnstatic_cast<pointer>(space.ralloc(sizeof(T)*count)); } pointerallocate(size_typecount,constvoid*consthint){ (void)hint; returnallocate(count); } voiddeallocate(pointerp,size_typecount){ space.rfree(static_cast<void*>(p),count); } /* *\briefConstructsanobject * *Constructsanobjectoftype\aTwiththeinitialvalueof\at *atthelocationspecifiedby\aelement.Thisfunctioncalls *the<i>placementnew()</i>operator. */ voidconstruct(pointerelement,const_referencet){ new(element)T(t); } voiddestroy(pointerelement){ element->~T(); } }; template<classT1,classT2> booloperator==(space_allocator<T1>const&al1, space_allocator<T2>const&al2)throw(){ return&al1.space==&al2.space; } template<classT1,classT2> booloperator!=(space_allocator<T1>const&al1, space_allocator<T2>const&al2)throw(){ return&al1.space!=&al2.space; } template<classT>structregion_allocator; template<> structregion_allocator<void>{ typedefvoid*pointer; typedefconstvoid*const_pointer; typedefvoidvalue_type; template<classU>structrebind{ typedefregion_allocator<U>other; }; }; template<classT> structregion_allocator{ typedefTvalue_type; typedefsize_tsize_type; typedefptrdiff_tdifference_type; typedefT*pointer; typedefTconst*const_pointer; typedefT&reference; typedefTconst&const_reference; template<classU>structrebind{ typedefregion_allocator<U>other; }; Region&region; region_allocator(Region&region)throw() :region(region){} region_allocator(region_allocatorconst&al)throw() :region(al.region){} template<classU> region_allocator(region_allocator<U>const&al)throw() :region(al.region){} pointeraddress(referencex)const{return&x;} const_pointeraddress(const_referencex)const{return&x;} size_typemax_size(void)constthrow(){ returnstd::numeric_limits<size_type>::max() /(sizeof(T)>0?sizeof(T):1); } pointerallocate(size_typecount){ returnstatic_cast<pointer>(region.ralloc(sizeof(T)*count)); } pointerallocate(size_typecount,constvoid*consthint){ (void)hint; returnallocate(count); } voiddeallocate(pointer*p,size_typecount){ region.rfree(static_cast<void*>(p),count); } voidconstruct(pointerelement,const_referencet){ new(element)T(t); } voiddestroy(pointerelement){ element->~T(); } }; /* *\briefTeststworegionallocatorsforequality * *Twoallocatorsareequalwheneachcanreleasestorageallocated *fromtheother. */ template<classT1,classT2> booloperator==(region_allocator<T1>const&al1, region_allocator<T2>const&al2)throw(){ return&al1.region==&al2.region; } /* *\briefTeststworegionallocatorsforinequality * *Twoallocatorsareequalwheneachcanreleasestorageallocated *fromtheother. */ template<classT1,classT2> booloperator!=(region_allocator<T1>const&al1, region_allocator<T2>const&al2)throw(){ return&al1.region!=&al2.region; } } //STATISTICS:kernel-memory