![]() |
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 |
Re: How to: Dynamic Auto resize
Why don't you just try it?
|
Re: How to: Dynamic array auto resize
i did and its slow esp. if its on loop
|
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. |
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?
|
Re: How to: Dynamic array auto resize
I told you the alternative. Estimate the number of entries you need.
|
Re: How to: Dynamic array auto resize
0..99999999 lets be realistic Luckie.
|
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.
|
Re: How to: Dynamic array auto resize
Zitat:
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? |
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. |
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