[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: [CPROG] _itoa



"Erwin S. Andreasen" wrote:
> 
> On Thu, 10 Jun 1999, Sune Fischer wrote:
> 
> > Findes der en måde at reskalere arrayen på uden først at slette den og
> > oprette den igen?
> 
> Nej, ikke naar den er oprettet med new. Lav en ny new[] og kopier
> elementerne hvis du vil bruge new (fx. fordi det er objekter du laver new
> af)
> 
> Men, siden et er kun chars, du kunne jo overveje at bruge calloc, men
> skjule det inden i en klasse, fx. Buffer:
> 
> // opretter fx en 128 bytes buffer per default
> Buffer *b = new Buffer;
> 
> // detekterer af der er brug for mere plads og laver en realloc
> b.add("256 bytes text here\n");
> 
> // laver en free
> delete b;

Jeg ved ikke hvor smart realloc er implementeret. Man kunne forestille
sig at den burde være lavet således at den blot lavede nogle trick med
MMU'en således at den ikke behøvede at kopiere elementerne over til et
nyt sted i hukommelsen. 

Det er dog ikke noget problem at kopiere elementerne over, HVIS du blot
sørger for at du fordobler array'ets størrelse hver gang.

Der findes en lidt længere udredning der kan vise at i dette tilfælde
vil det dynamiske array have den "amortiserede komplexitet"  O(1) (Det
vil sige du kan tilgå ethvert element i konstant tid, uafhængig af
arrayets størrelse.) Det er det samme som et statisk array, og meget
bedre end de hægtede lister man normalt er forfalden til at bruge hvis
man har brug for dynamisk plads, de har O(n)

Som en rigtig god forelæser på DTU, der nu desværre er blevet scoret af
den forp*lede IT højskole, sagde: "Linked lists are cute, but Real Men
use arrays"

Mvh Morten


 
Home   Subscribe   Mail Archive   Index   Calendar   Search

 
 
Questions about the web-pages to <www_admin>. Last modified 2005-08-10, 20:07 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] *