473,386 Members | 1,763 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

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

Oct 18 '07 #1
6 1560
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

Oct 18 '07 #2
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

Oct 18 '07 #3
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;

Oct 18 '07 #4
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 ?
Oct 18 '07 #5
GameboyHippo <ja************@gmail.comwrote:
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<intthough instead.
Oct 18 '07 #6
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
Oct 20 '07 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Andreas Suurkuusk | last post by:
Hi, I just noticed your post in the "C# memory problem: no end for our problem?" thread. In the post you implied that I do not how the garbage collector works and that I mislead people. Since...
2
by: Mike Peretz | last post by:
I am trying to optimize my C# program, but no matter what I try the application keeps eating memory. I verified all the references and even got special software to count references. I made sure all...
9
by: Mike P | last post by:
I know everything about reference counting and making sure you don't have large objects lying around. I have also profiled my app with multiple tools. I know about the fact GC collects memory but...
22
by: xixi | last post by:
hi, we are using db2 udb v8.1 for windows, i have changed the buffer pool size to accommadate better performance, say size 200000, if i have multiple connection to the same database from...
14
by: Alessandro Monopoli | last post by:
Hi all, I'm searching a PORTABLE way to get the available and total physical memory. Something like "getTotalMemory" and it returns the memory installed on my PC in bytes, and...
1
by: Nick Craig-Wood | last post by:
I've been dumping a database in a python code format (for use with Python on S60 mobile phone actually) and I've noticed that it uses absolutely tons of memory as compared to how much the data...
5
by: kumarmdb2 | last post by:
Hi guys, For last few days we are getting out of private memory error. We have a development environment. We tried to figure out the problem but we believe that it might be related to the OS...
1
by: Jean-Paul Calderone | last post by:
On Tue, 22 Apr 2008 14:54:37 -0700 (PDT), yzghan@gmail.com wrote: The test doesn't demonstrate any leaks. It does demonstrate that memory usage can remain at or near peak memory usage even after...
5
by: cham | last post by:
Hi, I am working on c++ in a linux system ( Fedora core 4 ), kernel version - 2.6.11-1.1369_FC4 gcc version - 4.0.0 20050519 ( Red Hat 4.0.0-8 ) In my code i am creating a vector to store...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.