From d306a7783afdb31b6e66ae0d04a3ebd3a1429029 Mon Sep 17 00:00:00 2001 From: Daniel Wallin Date: Fri, 6 Nov 2009 20:54:23 +0100 Subject: [PATCH] Allocate storage for instances with object_rep::allocate(). We would allocate storage using operator new for newly constructed instances. The memory would later be released with std::free() when the object_rep was destroyed. Additionally, this allows instances to be allocated inside the object_rep small buffer. --- luabind/detail/constructor.hpp | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/luabind/detail/constructor.hpp b/luabind/detail/constructor.hpp index b752cd3..60d97ac 100644 --- a/luabind/detail/constructor.hpp +++ b/luabind/detail/constructor.hpp @@ -39,6 +39,8 @@ struct construct template struct construct_aux<0, T, Pointer, Signature> { + typedef pointer_holder holder_type; + void operator()(argument const& self_) const { object_rep* self = touserdata(self_); @@ -50,7 +52,9 @@ struct construct_aux<0, T, Pointer, Signature> void* naked_ptr = instance.get(); Pointer ptr(instance.release()); - self->set_instance(new pointer_holder( + void* storage = self->allocate(sizeof(holder_type)); + + self->set_instance(new (storage) holder_type( ptr, registered_class::id, naked_ptr, cls)); } }; @@ -81,6 +85,8 @@ struct construct_aux # define BOOST_PP_LOCAL_LIMITS (1,N) # include BOOST_PP_LOCAL_ITERATE() + typedef pointer_holder holder_type; + void operator()(argument const& self_, BOOST_PP_ENUM_BINARY_PARAMS(N,a,_)) const { object_rep* self = touserdata(self_); @@ -92,7 +98,9 @@ struct construct_aux void* naked_ptr = instance.get(); Pointer ptr(instance.release()); - self->set_instance(new pointer_holder( + void* storage = self->allocate(sizeof(holder_type)); + + self->set_instance(new (storage) holder_type( ptr, registered_class::id, naked_ptr, cls)); } }; -- 2.11.4.GIT