Re: alloca / _alloca / dynamic stack memory
- From: "Doug Harrison [MVP]" <dsh@xxxxxxxx>
- Date: Thu, 08 Mar 2007 21:34:32 -0600
On Thu, 8 Mar 2007 12:57:33 -0800, Michael Crawley
<MichaelCrawley@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote:
class _StackAlloc{};
const _StackAlloc StackAlloc; // Used only to resolve overloaded
method/operator
void* Object::operator new(size_t size, const _StackAlloc& stackAlloc)
{
// Allocation on stack
// ...
// Return Pointer to allocated memory
__asm push pointer onto stack;
__asm jmp (return address); // Jump out of the current stack frame
};
// Calls destructor, but does not free memory until the
// current function returns
void Object::Dispose(const StackAlloc& stackAlloc)
{
// Invoke Distructor
this->~Object(); // Virtual Base destructor
// Perform other operations specific to this
// memory allocation method
// ...
};
class String : public Object
{
public:
// ...
private:
~String(){...}; // Means this type can only be on allocated on dynamic
memory
};
int main()
{
String str("bad"); // Compiler error, cannot access private distructor
String* str1 = new(Heap) String("better"); // Ok
String* str2 = new String("better"); // Ok
String* str3 = new(StackAlloc) String("better"); // OK, faster than
str1/str2
What does String have for data?
--
Doug Harrison
Visual C++ MVP
.
- References:
- Re: alloca / _alloca / dynamic stack memory
- From: Igor Tandetnik
- Re: alloca / _alloca / dynamic stack memory
- From: Igor Tandetnik
- Re: alloca / _alloca / dynamic stack memory
- From: Michael Crawley
- Re: alloca / _alloca / dynamic stack memory
- Prev by Date: Re: "Type-safe" sprintf
- Next by Date: Serialized r/w access to a collection from multiple processes - DLL or EXE?
- Previous by thread: Re: alloca / _alloca / dynamic stack memory
- Next by thread: Re: alloca / _alloca / dynamic stack memory
- Index(es):
Relevant Pages
|
Loading