Delphi-PRAXiS
Seite 1 von 2  1 2      

Delphi-PRAXiS (https://www.delphipraxis.net/forum.php)
-   Win32/Win64 API (native code) (https://www.delphipraxis.net/17-win32-win64-api-native-code/)
-   -   Delphi How to: Dynamic array auto resize (https://www.delphipraxis.net/146107-how-dynamic-array-auto-resize.html)

nanix 13. Jan 2010 16:36


How to: Dynamic array auto resize
 
Hello


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

setlegnth(array,somechangingvariable

Luckie 13. Jan 2010 16:37

Re: How to: Dynamic Auto resize
 
Why don't you just try it?

nanix 13. Jan 2010 16:38

Re: How to: Dynamic array auto resize
 
i did and its slow esp. if its on loop

Luckie 13. Jan 2010 16:44

Re: How to: Dynamic array auto resize
 
Why do you ask, if you already know it? :wall:

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.

nanix 13. Jan 2010 16:54

Re: How to: Dynamic array auto resize
 
Well what to use instead thats why i asked is there an alternative? How do i know how much processes are you running?

Luckie 13. Jan 2010 16:58

Re: How to: Dynamic array auto resize
 
I told you the alternative. Estimate the number of entries you need.

nanix 13. Jan 2010 17:00

Re: How to: Dynamic array auto resize
 
0..99999999 lets be realistic Luckie.

Luckie 13. Jan 2010 17:05

Re: How to: Dynamic array auto resize
 
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.

Mithrandir 13. Jan 2010 17:10

Re: How to: Dynamic array auto resize
 
Zitat:

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?

nanix 13. Jan 2010 17:16

Re: How to: Dynamic array auto resize
 
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? :wall:


@ Daniel

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


are you crazy and this is only for 32 bit :lol:


Alle Zeitangaben in WEZ +1. Es ist jetzt 10:47 Uhr.
Seite 1 von 2  1 2      

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024 by Thomas Breitkreuz