AGB  ·  Datenschutz  ·  Impressum  







Anmelden
Nützliche Links
Registrieren
Zurück Delphi-PRAXiS Programmierung allgemein Win32/Win64 API (native code) Delphi How to: Dynamic array auto resize
Thema durchsuchen
Ansicht
Themen-Optionen

How to: Dynamic array auto resize

Ein Thema von nanix · begonnen am 13. Jan 2010 · letzter Beitrag vom 13. Jan 2010
Thema geschlossen
Seite 1 von 2  1 2      
nanix
(Gast)

n/a Beiträge
 
#1

How to: Dynamic array auto resize

  Alt 13. Jan 2010, 15:36
Hello


is this possible to automaticly resize dynamic array if some variable changes?
Delphi-Quellcode:
var
somechangingvariable:integer;

setlegnth(array,somechangingvariable
 
Benutzerbild von Luckie
Luckie

Registriert seit: 29. Mai 2002
37.621 Beiträge
 
Delphi 2006 Professional
 
#2

Re: How to: Dynamic Auto resize

  Alt 13. Jan 2010, 15:37
Why don't you just try it?
Michael
Ein Teil meines Codes würde euch verunsichern.
 
nanix
(Gast)

n/a Beiträge
 
#3

Re: How to: Dynamic array auto resize

  Alt 13. Jan 2010, 15:38
i did and its slow esp. if its on loop
 
Benutzerbild von Luckie
Luckie

Registriert seit: 29. Mai 2002
37.621 Beiträge
 
Delphi 2006 Professional
 
#4

Re: How to: Dynamic array auto resize

  Alt 13. Jan 2010, 15:44
Why do you ask, if you already know it?

Resizing an array inside a loop is not recommended because of the internal memory management. If you resize a dynamic array the new memory is allocated and then the contents of the old array is copied into the new allocated memory. This takes time and wastes memory because the old memory is not freed.

It is better if you estimate the space needed and resize the array once if you need more entries. If you have finished you truncate the array to its entries.
Michael
Ein Teil meines Codes würde euch verunsichern.
 
nanix
(Gast)

n/a Beiträge
 
#5

Re: How to: Dynamic array auto resize

  Alt 13. Jan 2010, 15:54
Well what to use instead thats why i asked is there an alternative? How do i know how much processes are you running?
 
Benutzerbild von Luckie
Luckie

Registriert seit: 29. Mai 2002
37.621 Beiträge
 
Delphi 2006 Professional
 
#6

Re: How to: Dynamic array auto resize

  Alt 13. Jan 2010, 15:58
I told you the alternative. Estimate the number of entries you need.
Michael
Ein Teil meines Codes würde euch verunsichern.
 
nanix
(Gast)

n/a Beiträge
 
#7

Re: How to: Dynamic array auto resize

  Alt 13. Jan 2010, 16:00
0..99999999 lets be realistic Luckie.
 
Benutzerbild von Luckie
Luckie

Registriert seit: 29. Mai 2002
37.621 Beiträge
 
Delphi 2006 Professional
 
#8

Re: How to: Dynamic array auto resize

  Alt 13. Jan 2010, 16:05
Hey. Can't you do anything on your own? Open your task manager and look how many processes are running. Then you add, let's say, 15% or 20%. On my machine are 19 processes running and at my machine at work about 40 after login. To be on the safe side I would initialize the array with 60 entries.
Michael
Ein Teil meines Codes würde euch verunsichern.
 
Benutzerbild von Mithrandir
Mithrandir
(CodeLib-Manager)

Registriert seit: 27. Nov 2008
Ort: Delmenhorst
2.379 Beiträge
 
#9

Re: How to: Dynamic array auto resize

  Alt 13. Jan 2010, 16:10
Zitat von nanix:
0..99999999 lets be realistic Luckie.
Bullshit.

Estimate it: On a 32bit OS it might be possible to run 65,535 processes (unsigned int). So you divide this Value by 2, and there you have.

I'm wondering why you need to "adjust" the Array. If a process is being killed, simply put the length of your array to zero and refill it.

Or would you like to do something else?
米斯蘭迪爾
"In einer Zeit universellen Betruges wird das Aussprechen der Wahrheit zu einem revolutionären Akt." -- 1984, George Orwell
 
nanix
(Gast)

n/a Beiträge
 
#10

Re: How to: Dynamic array auto resize

  Alt 13. Jan 2010, 16:16
No becouse he apparently he estimates everything in life.It doesnt go that way!Why would you want to estimate if you can simply do

Setlength(Processes,0);
Setlength(Processes,Instances);
//Refill

where instances changes on 2 s interval it will change if you open/close processes.



Why estimate?


@ Daniel

a:array [0..32767] of integer;


are you crazy and this is only for 32 bit
 
Thema geschlossen
Seite 1 von 2  1 2      


Forumregeln

Es ist dir nicht erlaubt, neue Themen zu verfassen.
Es ist dir nicht erlaubt, auf Beiträge zu antworten.
Es ist dir nicht erlaubt, Anhänge hochzuladen.
Es ist dir nicht erlaubt, deine Beiträge zu bearbeiten.

BB-Code ist an.
Smileys sind an.
[IMG] Code ist an.
HTML-Code ist aus.
Trackbacks are an
Pingbacks are an
Refbacks are aus

Gehe zu:

Impressum · AGB · Datenschutz · Nach oben
Alle Zeitangaben in WEZ +1. Es ist jetzt 19:22 Uhr.
Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024 by Thomas Breitkreuz