nntp2http.com
Posting
Suche
Optionen
Hilfe & Kontakt

new , delete[] und malloc, realloc, calloc

Von: Robert Hartmann (robert_hartmann@gmx.net) [Profil]
Datum: 02.07.2009 17:36
Message-ID: <h2ik3n$ptk$1@ariadne.rz.tu-clausthal.de>
Newsgroup: de.comp.lang.iso-c++
Hallo zusammen,

Kennt Ihr eine sinnvolle Möglichkeit zur Implementierung von  resizeFie
ld.

Zuerst hab ich vermutet, dass ich die cfunktion malloc benutzen könnte,
aber irgendwie scheint das nicht ganz so zugehen, wie ich dachte(siehe
unten).

Besten Dank,
Gruß Robert


class Test{

private:
unsigned char * theField;
unsigned int size; //in Bytes

public:
Test(const unsigned int Anzahl);

resizeField(const unsigned int Anzahl);

virtual ~Test();

};

Test::Test(const unsigned int Anzahl)
:size(Anzahl*sizeof(char))
{
theField = new unsigned char[Anzahl];
}

Test::~Test(){
size = 0;
delete[] this->theField;
}


Test::resizeField(const unsigned int Anzahl){
size = Anzahl;
unsigned char * TEMP = NULL;
TEMP = malloc(Anzahl*sizeof(char));
if (TEMP != NULL){
delete[] this->theField;
this->theField = TEMP;
}
}

[ Auf dieses Posting antworten ]

Antworten