[an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] (none) [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] (none) [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive]
 
[an error occurred while processing this directive] [an error occurred while processing this directive]
Skåne Sjælland Linux User Group - http://www.sslug.dk Home   Subscribe   Mail Archive   Forum   Calendar   Search
MhonArc Date: [Date Prev] [Date Index] [Date Next]   Thread: [Date Prev] [Thread Index] [Date Next]   MhonArc
 

Re: [PROGRAMMERING] [C++]heap allokering?



Anders Hellerup Madsen <sslug@sslug> skrev den 11-Aug-04:

> Problemet kommer når jeg har lyst til at bruge funktionerne til at
> allokere plads til c++ objekter, altså som en slags erstatning for
> new og delete. Kan det overhovedet lade sig gøre?

Du kan lave nye "operator new" og "operator delete", nedenfor er et
tosset eksempel. Til din brug vil du nok blot lade dem kalde dine
heap_malloc() og heap_free().

                           -------------------


#include <iostream>

void* operator new(size_t size)
{
    static char a;
    return &a;
}

void operator delete(void*)
{
}

int main()
{
    char* a = new char;
    char* b = new char;

    *a = 'a';
    *b = 'b';

    std::cout << *a << std::endl;
}

                           -------------------

Anders.


 
Home   Subscribe   Mail Archive   Index   Calendar   Search

 
 
Questions about the web-pages to <www_admin>. Last modified 2005-08-10, 22:44 CEST [an error occurred while processing this directive]
This page is maintained by [an error occurred while processing this directive]MHonArc [an error occurred while processing this directive] # [an error occurred while processing this directive] *