|
|
|
|
||||||
![]() |
|
|
LinkBack | Outils de la discussion |
|
|
#1 |
|
Messages: n/a
Hébergeur: |
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 |
|
|
|
#2 |
|
Messages: n/a
Hébergeur: |
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 |
|
|
|
#3 |
|
Messages: n/a
Hébergeur: |
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 tellme if there;s a mistake |
|
|
|
#4 |
|
Messages: n/a
Hébergeur: |
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; |
|
|
|
#5 |
|
Messages: n/a
Hébergeur: |
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 ? |
|
|
|
#6 |
|
Messages: n/a
Hébergeur: |
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. |
|
|
|
#7 |
|
Messages: n/a
Hébergeur: |
> 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 |
|
![]() |
| Outils de la discussion | |
|
|