Delphi-PRAXiS

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 15: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 15:37

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

nanix 13. Jan 2010 15:38

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

Luckie 13. Jan 2010 15: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 15: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 15:58

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

nanix 13. Jan 2010 16:00

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

Luckie 13. Jan 2010 16: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 16: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 16: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:

Luckie 13. Jan 2010 16:20

Re: How to: Dynamic array auto resize
 
If you know the number of processes running you don't have to estimate of course. So what's your problem?

@Daniel: 32768 Prozesse? :mrgreen: Ok, damit bist du wohl ziemlich sicher auf der sicheren Seite. Aber ob Windows das noch mitmachen würde. ;)

Daniel 13. Jan 2010 16:27

Re: How to: Dynamic array auto resize
 
Nanix (David), eight weeks ago we had a little "conversation". maybe you remember it. I stopped answering your messages after you sent to me the following words: Aww man when i see your ass ill smack every tooth you got believe that!



erm ... do you relly think that I want to have you here in my forum? are you really that stupid? go away. your accound will be closed.


Alle Zeitangaben in WEZ +1. Es ist jetzt 15:14 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-2025 by Thomas Breitkreuz