[an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] (none) [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] (none) [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive]
 
[an error occurred while processing this directive] [an error occurred while processing this directive]
Skåne Sjælland Linux User Group - http://www.sslug.dk Home   Subscribe   Mail Archive   Forum   Calendar   Search
MhonArc Date: [Date Prev] [Date Index] [Date Next]   Thread: [Date Prev] [Thread Index] [Date Next]   MhonArc
 

Re: [CPROG] Dynamisk alloceret arrays



Thomas M. wrote:
[snip]
>  Er der en mulighed for at lave dynamisk allocerede arrays, således at de
> kan vokse, når der bliver brug for det?

   Den normalle maade at goere dette paa er vha. malloc() og/eller
calloc(). Siden dine arrays skal vokse efter at du har allokeret
hukommelse til dem er du ogsaa noedt til at bruge realloc(). Se
man-siderne paa alle tre.

   At faa et array til at vokse ved noedvendighed kan goeres paa flere
maader. Du kan f.eks. bruge en grow() funktion som enten kaldes manuelt
eller automatisk naar indexen paa et array overskrides. I grow() kan du
saa realloce arrayet til nuvaerende_stoerelse+delta (delta er det antal
elementer arrayet skal vokse med. Det er en daarlig ide -- normalt -- at
bruge et delta paa 1 da det resulterer i mange kald til realloc()).

   Uden helt at vide hvad du skal bruge dette til, er der andre
loesninger paa det samme problem. Haegtede lister, hashtables, tries,
m.v. er alle maader at have lister med arbitraere laengder. Hvis det
udelukkende er strenge der er problemmet, saa er dynamiske arrays dog
nok sagen. Haaber af dette kan bruges som et udgangspunkt. Hvis du vil
have mere specifikke detaljer, saa skal du bare sig til.

-- 
| Per Vognsen (Randers - Denmark)| "Superstition is a  word the |
| Mail: <sslug@sslug>   | ignorant  use   to  describe |
| Voice: +45 20639009            | their own ignorance." - Sifu |


 
Home   Subscribe   Mail Archive   Index   Calendar   Search

 
 
Questions about the web-pages to <www_admin>. Last modified 2005-08-10, 20:07 CEST [an error occurred while processing this directive]
This page is maintained by [an error occurred while processing this directive]MHonArc [an error occurred while processing this directive] # [an error occurred while processing this directive] *