PHWinfo banniere

Titres
PORTAIL ANNUAIRE ARTICLES COMPARATEUR HÉBERGEURS DEVIS FORUMS RÉDUCTEUR D'URL
Précédent   PHWinfo > Autres forums > Forum Programmation & Conception > comp.lang.cplus > Allocationg memory: contigously ?
S'inscrire FAQ Membres Recherche Messages du jour Marquer les forums comme lus
Allocationg memory: contigously ?

Réponse
 
LinkBack Outils de la discussion
Vieux 18/10/2007, 16h55   #1
horacius.rex@gmail.com
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Allocationg memory: contigously ?

Hi,

if I allocate memory in a simple program like

int* pint1=new[1000];
int* pint2=new[1000];
int* pint3=new[1000];

then memory is allocated on the heap. My question is if this three
"memory fragmetns" are allocated contigously. And if not, what could I
do to allocate them contigously.

Thanks

  Réponse avec citation
Vieux 18/10/2007, 17h03   #2
robin
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Allocationg memory: contigously ?

On Oct 18, 11:55 pm, horacius....@gmail.com wrote:
> Hi,
>
> if I allocate memory in a simple program like
>
> int* pint1=new[1000];
> int* pint2=new[1000];
> int* pint3=new[1000];
>
> then memory is allocated on the heap. My question is if this three
> "memory fragmetns" are allocated contigously. And if not, what could I
> do to allocate them contigously.
>
> Thanks


1). They might be allocated contigously but this is not always
guaranteed.
2). Honestly I'm not quite clear about this point, I think you might
need to define your own memory allocation strategy, using some
"placement new operator" or something...

Regards,
-robin

  Réponse avec citation
Vieux 18/10/2007, 17h04   #3
farbe90@gmail.com
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Allocationg memory: contigously ?

On Oct 18, 8:55 pm, horacius....@gmail.com wrote:
> Hi,
>
> if I allocate memory in a simple program like
>
> int* pint1=new[1000];
> int* pint2=new[1000];
> int* pint3=new[1000];
>
> then memory is allocated on the heap. My question is if this three
> "memory fragmetns" are allocated contigously. And if not, what could I
> do to allocate them contigously.
>
> Thanks



hey
im sure sbout that memory may not be contiguous....since it is done
dynamically...rather never..coz u can take that probability as
1:trillion.
and about the thing im not 140% sure is that nthng can be done about
it...only thing u can do is that u can join them by linking stacks..
well thats all i know frm my school... ...im still studying..pl tell
me if there;s a mistake

  Réponse avec citation
Vieux 18/10/2007, 17h16   #4
GameboyHippo
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Allocationg memory: contigously ?

On Oct 18, 12:04 pm, farb...@gmail.com wrote:
> On Oct 18, 8:55 pm, horacius....@gmail.com wrote:
>
> > Hi,

>
> > if I allocate memory in a simple program like

>
> > int* pint1=new[1000];
> > int* pint2=new[1000];
> > int* pint3=new[1000];

>
> > then memory is allocated on the heap. My question is if this three
> > "memory fragmetns" are allocated contigously. And if not, what could I
> > do to allocate them contigously.

>
> > Thanks

>
> hey
> im sure sbout that memory may not be contiguous....since it is done
> dynamically...rather never..coz u can take that probability as
> 1:trillion.
> and about the thing im not 140% sure is that nthng can be done about
> it...only thing u can do is that u can join them by linking stacks..
> well thats all i know frm my school... ...im still studying..pl tell
> me if there;s a mistake


y do people talk lik thiz. I mean seriously people. Is it that hard
to communicate using complete words? To me, it topples your
credibility.

Okay, now for something that really matters. Will the data be
contigously? Maybe. Maybe not. How to make them contigous: Here's
what I would do.

int* pint=new[3000];
int* pint1 = pint;
int* pint2 = pint + 1000;
int* pint3 = pint + 2000;

  Réponse avec citation
Vieux 18/10/2007, 17h23   #5
tragomaskhalos
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Allocationg memory: contigously ?

On Oct 18, 4:55 pm, horacius....@gmail.com wrote:
> Hi,
>
> if I allocate memory in a simple program like
>
> int* pint1=new[1000];
> int* pint2=new[1000];
> int* pint3=new[1000];
>
> then memory is allocated on the heap. My question is if this three
> "memory fragmetns" are allocated contigously. And if not, what could I
> do to allocate them contigously.
>


No - there is almost certainly going to be some extra
stuff before each block which prevents them being
contiguous. To ensure contiguity, you could do this:

int* p1 = new int[3000];
int* p2 = p1 + 1000;
int* p3 = p2 + 1000;

Obviously in this case you must be sure to only
delete[] the p1 pointer.

But why do you care about contiguity ?


  Réponse avec citation
Vieux 18/10/2007, 17h29   #6
Daniel T.
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Allocationg memory: contigously ?

GameboyHippo <jasonwthompson@gmail.com> wrote:

> Okay, now for something that really matters. Will the data be
> contigously? Maybe. Maybe not. How to make them contigous: Here's
> what I would do.
>
> int* pint=new[3000];
> int* pint1 = pint;
> int* pint2 = pint + 1000;
> int* pint3 = pint + 2000;


That would work, I'd make pint a vector<int> though instead.
  Réponse avec citation
Vieux 21/10/2007, 00h49   #7
Marcin Kalicinski
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Allocationg memory: contigously ?

> if I allocate memory in a simple program like
>
> int* pint1=new[1000];
> int* pint2=new[1000];
> int* pint3=new[1000];
>
> then memory is allocated on the heap. My question is if this three
> "memory fragmetns" are allocated contigously. And if not, what could I
> do to allocate them contigously.


int *bigfatpint = new int[3000];
int *pint1 = bigfatpint;
int *pint2 = bigfatpint + 1000;
int *pint3 = bigfatpint + 2000;

cheers,
Marcin


  Réponse avec citation
Réponse


Outils de la discussion

Règles de messages
Vous ne pouvez pas créer de nouvelles discussions
Vous ne pouvez pas envoyer des réponses
Vous ne pouvez pas envoyer des pièces jointes
Vous ne pouvez pas modifier vos messages

Les balises BB sont activées : oui
Les smileys sont activés : oui
La balise [IMG] est activée : oui
Le code HTML peut être employé : non
Trackbacks are oui
Pingbacks are oui
Refbacks are oui


Fuseau horaire GMT +1. Il est actuellement 13h47.


Édité par : vBulletin® version 3.7.2
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC5 Tous droits réservés.
Version française #16 par l'association vBulletin francophone
PHWinfo est un site Éducation Sans Frontières
Ad Management by RedTyger
©Tous droits réservés par les parties respectives
Page generated in 0,10869 seconds with 15 queries