Az Ego kicsiny világa ;-)
Menü
 
Bejelentkezés
Felhasználónév:

Jelszó:
SúgóSúgó
Elfelejtettem a jelszót
 
Olvasgatom...
 
 
társalgó
Név:

Üzenet:
:)) :) :@ :? :(( :o :D ;) 8o 8p 8) 8| :( :'( ;D :$
 
Site Meter


moon phases
~ Computer related
~ Computer related : The structure of a dynamic array

The structure of a dynamic array

Ch. Oe.  2007.05.13. 07:25

If you want to access an array you need to know the number of the field

1. WHAT IS AN ARRAY?
An array is a variable type. It intends to give access on a large number of variables. An array like a street of houses, each with a house-number and a certain houses. The house number is the number you access a array field with and the house and it's content represents the data in the array field.  
To declare an array you need to tell the compiler how much variables the array should have and of which type they should be:  
  ArrayName : array[OrdinalStartValue..OrdinalEndValue] of VariabelType;  
If you want to access an array you need to know the number of the field:  
  VariableInField := ArrayName[NumberOfField];  
An array can be have more dimensions. An 2-D array would be like a number of streets all named with numbers 1,2,3... and each with houses. To get to a house you need street number and house number. The declaration is very similar:  
  ArrayName : array[FirstDimensionStart..FirstDimensionEnd] of array[SecondDimensionStart..SecondDimensionEnd] of VariableType  
or  
  ArrayName : array[1stDStart..1stDEnd, 2ndDStart..2ndDEnd] of VariableType
2. WHAT IS THE PROBLEM?
Arrays are very big that's the problem. An array is static, i.d. it exists from the construction of the object(see Object Oriented Programming) or starting of the program to it's destruction or ending, which brings the problem that the writer of the program has to know in the moment of the construction how large the array has to be and has no chance to resize the array. What this means is very easy, if you don't know how large the array will be and you cannot resize it, you have to choose the biggest size that you could imagine to occur. You can easily think of the memory you'll waste, when creating such a big array, that in most times will be empty!!  
When the variables are small then this doesn't matter you might say, but think of an array of objects, each which ten, twenty variables, methods..., mh,..., uh..., that's not right I have to admit. Object is a bad example, because when you create an array of objects, it is made up out of Pointers which point at the object, so you can leave the objects uncreated and create them on demand. Okay, but I know that you use dynamic arrays also for objects, I gonna ask about this. So consider strings, 255 byte in size... :). Poor reasoning I have to admit, so althought I cannot say exactely why I can say how...
3. HOW IS THE PROBLEM SOLVED?
The Problem is solved by creating an array of Pointers on the elements and creating an Pointer that points on this array:  
type
  TDataStore = String;
  PDataStore = ^TDataStore;
  TDataStoreList = array[StartValue..EndValue] of PDataStore;
  PDataStoreList = ^TDataStoreList;
 
In the beginning when the list should be empty you let the fDataStoreList (a variable of type PDataStoreList(see Naming and Formating Convention)) point on nothing and set up an counter for the elements with starting value 0, named fCount. When you want to add an item you have to:
1. Create an memory area for fCount + 1 pointers on TDataStore.
2. Move all entries from the former memory area the Pointer on the list was pointing to the new list.
3. Point on this area with your pointer on the list.
4. Free the old memory area.
5. Point on the item, which should be added, with a pointer, which is set up as entry No. fCount +1 of the list.(This means the pointer is added to the memory field).
6. Increase fCount by 1.
 
Dynamic Arrays:
Ch.Oe.

 
Hasznos Linkek
 
Melegedj a tüznél
 
Movie Linkek:
 
Érdekes honlapok:
 
Homepages:
 
Zene, klippek:
 

NOTE:

All Pictures belong to the respected artists and movie companies. No money is made in the usage or making of this site. Please support the artists by buying their movies. I do not upload any of these pictures and images. None of these pictures and photos are mine. If Your picture, image or photo is on here and you want it off, email me and I will take it off right away: 

  zen.titusz@gmail.com 

 


Mindig tudnod kell, melyik kikötõ felé tartasz. - ROSE HARBOR, a mi városunk - FRPG    *****    A boroszkányok gyorsan megtanulják... Minden mágia megköveteli a maga árát. De vajon mekkora lehet ez az ár? - FRPG    *****    Alkosd meg a saját karaktered, és irányítsd a sorsát! Vajon képes lenne túlélni egy ilyen titkokkal teli helyen? - FRPG    *****    why do all monsters come out at night - FRPG - Csatlakozz közénk! - Írj, és éld át a kalandokat!    *****    Aki szörnyekkel küzd, vigyázzon, nehogy belõle is szörny váljék. S ha hosszasan tekintesz egy örvénybe, az örvény vissza    *****    Rose Harbor, ahol a tenger suttog és a múlt sosem tûnik el teljesen. - FRPG - csatlakozz közénk te is :)    *****    Egy kikötõ, ahol minden hullám egy új kezdetet ígér. Rose Harbor, több mint egy város, egy világ a világ mögött.    *****    Rose Harbor &#8211; kisvárosi báj, nagy titkokkal - légy részese te is ennek a kalandnak :) - FRPG    *****    Óceán, erdõ, csillagfény &#8211; minden ösvény Rose Harborba vezet - aktív FRPG közösség    *****    Itachi Shinden 1. kötet Magyarul elérhetõ a konoha.hu -n. Nézzetek be! *** Itachi Shinden 1. kötet Magyarul elérhetõ!!!    *****    ÁGICAKÖNYVTÁRA - KÖNYVEK, KÖNYVEK, KÖNYVEK - ÁGICAKÖNYVTÁRA    *****    MOVIE-NIGHT -> Filmek, Sorozatok <- MOVIE-NIGHT    *****    Movie-    *****    Játssz a színekkel keress szebbnél szebb képeket, építs, szépítsd a portálod, hogy szebb és színesebb legyen a világod!    *****    Debrecen Huszti Lakóparki napelemes családiház eladó. 06209911123 Debrecen Huszti Lakóparki napelemes családiház eladó.    *****    Pont ITT Pont MOST! Pont NEKED! Már fejlesztés alatt is szebbnél színes szebb képek! Ha gondolod gyere less be!    *****    Kedves Csokoládé kedvelõk! Segítségeteket kérném a kérdõívem kitöltéséhez! Témája a CSOKOLÁDÉ MÁRKÁK! Köszön    *****    Homlokzati hõszigetelés! Vállaljuk családi házak, lakások, nyaralók és egyéb épületek homlokzati hõszigetelését!    *****    * Beugrós munkavállalók éjjel-nappal. * Beugrós munkavállalók éjjel-nappal. * Beugrós munkavállalók éjjel-nappal. *    *****    Elindult a Játék határok nélkül rajongói oldal! Ha te is szeretted a '90-es évek népszerû mûsorát, nézz be ide!