Article View: fr.comp.lang.c
Article #15419Re: Tableau: différence entre pile et tas
From: Emmanuel Delahaye
Date: Wed, 28 Sep 2005 17:14
Date: Wed, 28 Sep 2005 17:14
68 lines
2755 bytes
2755 bytes
dab@acri-st.fr wrote on 28/09/05 :
> Bonjour � tous
>
> J'ai un bout de code qui utilise des tables:
> #define NB_MAX_GRID_POINT 2621442
> #define NB_NEIGHBOR 6
>
> t_grid_point* gridPointTable[NB_MAX_GRID_POINT];
Un tableau de pointeurs. Ok. La valeur est �norme. Elle doit �re
imp�rativement static ou allou�e.
> t_sorted_grid_point distTable[NB_MAX_GRID_POINT][NB_NEIGHBOR];
Idem (encore pire)...
> Pour commencer � developper, j'avais une valeur de 50 pour
> NB_MAX_GRID_POINT,
> mais maintenant que j'utilise la v�ritable valeur de
> NB_MAX_GRID_POINT,
> je me prend un segmentation fault � l'execution.
>
> Du coup, je me dis que c'est la taille de mon tableau en pile qui pose
> soucis,
Ben oui. Trop gros...
> je vais donc allouer mon tableau dans le tas.
>
> et hop:
> gridPointTable = malloc(NB_MAX_GRID_POINT*sizeof(void *));
Pourquoi (void *) ?
t_grid_point* gridPointTable = malloc (NB_MAX_GRID_POINT * sizeof
*gridPointTable);
> distTable = malloc(NB_MAX_GRID_POINT*sizeof(void *));
t_sorted_grid_point* distTable = malloc (NB_MAX_GRID_POINT *
sizeof*distTable);
> for(inc=0; inc<NB_MAX_GRID_POINT; inc++) {
> distTable[inc] = malloc(NB_NEIGHBOR*sizeof(t_sorted_grid_point));
distTable[inc] = malloc (NB_NEIGHBOR * sizeof *distTable[inc]);
> }
>
> Est-ce que je suis cens� utiliser mes tableaux diff�rements
> maintenant?
Non.
> Qu'est-ce que je dois prendre comme pr�caution suppl�mentaire?
Aucune � part la lib�ration � la fin. Garder en t�te que la m�moire
n'est pas continue.
--
Emmanuel
The C-FAQ: http://www.eskimo.com/~scs/C-faq/faq.html
The C-library: http://www.dinkumware.com/refxc.html
"There are 10 types of people in the world today;
those that understand binary, and those that dont."
Technical Details
Message-ID:
<mn.e4827d59f351819c.15512@YOURBRAnoos.fr>Path:
arc1-ca.pugleaf.net!g2news1.google.com!news1.google.com!proxad.net!infeed-2.proxad.net!news18-e.free.fr!not-for-mailReferences:
<1127923112.347881.79740@z14g2000cwz.googlegroups.com>Show Full Headers
Complete Article Headers
X-Google-Thread: f9822,9ee84542aed426f5 X-Google-Attributes: gidf9822,public X-Google-Language: FRENCH,ASCII Path: arc1-ca.pugleaf.net!g2news1.google.com!news1.google.com!proxad.net!infeed-2.proxad.net!news18-e.free.fr!not-for-mail Subject: Re: Tableau: différence entre pile et tas From: "Emmanuel Delahaye" <emdel@YOURBRAnoos.fr> References: <1127923112.347881.79740@z14g2000cwz.googlegroups.com> Newsgroups: fr.comp.lang.c Message-ID: <mn.e4827d59f351819c.15512@YOURBRAnoos.fr> X-Newsreader: MesNews/1.04.00.00-fr Date: Wed, 28 Sep 2005 19:14:33 +0200 MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-15"; format=flowed Content-Transfer-Encoding: 8bit Lines: 70 Organization: Guest of ProXad - France NNTP-Posting-Date: 28 Sep 2005 19:14:34 MEST NNTP-Posting-Host: 81.65.109.78 X-Trace: 1127927674 news18-e.free.fr 31829 81.65.109.78:10685 X-Complaints-To: abuse@proxad.net