473,396 Members | 1,789 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,396 software developers and data experts.

Large Buffer Memory Management

Hi Folks,

This may be somewhat off-topic, but it sorta fits.

This is a C++ application that will be built using gcc and targeted
(via the wonderful wxWidgets library) for both Windoze and Linux.

Let's say I want to maintain an array of 16-bit integers that can be 100's
of MBs in length. What's the best way to do this? Should I simply
create the array and let the OS deal with swapping? Or should I
use a file as temporary space and fseek through it? Is there some
other better way?

Your thoughts would be appreciated.
--
% Randy Yates % "How's life on earth?
%% Fuquay-Varina, NC % ... What is it worth?"
%%% 919-577-9882 % 'Mission (A World Record)',
%%%% <ya***@ieee.org % *A New World Record*, ELO
http://home.earthlink.net/~yatescr
Aug 8 '06 #1
9 3475
Randy Yates wrote:
This may be somewhat off-topic, but it sorta fits.
It don't, really. If you're concerned with swapping, it's not
a language problem: C++ does not define swapping. :-/
This is a C++ application that will be built using gcc and targeted
(via the wonderful wxWidgets library) for both Windoze and Linux.
Then you need to ask in Windows or Linux newsgroups (or both).
Let's say I want to maintain an array of 16-bit integers that can be
100's of MBs in length. What's the best way to do this? Should I
simply
create the array and let the OS deal with swapping? Or should I
use a file as temporary space and fseek through it? Is there some
other better way?
Start from the simplest solution you can think of, and only if it does
*not* work for you, improve it.

I bet you if you ask in the newsgroup dedicated to your OS, you will
find much more information about how to conform to OS' functionality
related to maintaining large arrays, than in any language newsgroup.

V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
Aug 8 '06 #2
"Victor Bazarov" <v.********@comAcast.netwrites:
Randy Yates wrote:
>This may be somewhat off-topic, but it sorta fits.

It don't, really. If you're concerned with swapping, it's not
a language problem: C++ does not define swapping. :-/
>This is a C++ application that will be built using gcc and targeted
(via the wonderful wxWidgets library) for both Windoze and Linux.

Then you need to ask in Windows or Linux newsgroups (or both).
>Let's say I want to maintain an array of 16-bit integers that can be
100's of MBs in length. What's the best way to do this? Should I
simply
create the array and let the OS deal with swapping? Or should I
use a file as temporary space and fseek through it? Is there some
other better way?

Start from the simplest solution you can think of, and only if it does
*not* work for you, improve it.

I bet you if you ask in the newsgroup dedicated to your OS, you will
find much more information about how to conform to OS' functionality
related to maintaining large arrays, than in any language newsgroup.
Thanks for that suggestion, Victor. I will check there.

If, in the mean time, any other folks here have ideas, I'd like to hear them.
I'm not sure this problem is so far divorced from the language that this is
not a reasonable place to ask.
--
% Randy Yates % "Though you ride on the wheels of tomorrow,
%% Fuquay-Varina, NC % you still wander the fields of your
%%% 919-577-9882 % sorrow."
%%%% <ya***@ieee.org % '21st Century Man', *Time*, ELO
http://home.earthlink.net/~yatescr
Aug 8 '06 #3
In article <m3************@dsp.awid.com>, Randy Yates <ya***@ieee.org>
wrote:
Let's say I want to maintain an array of 16-bit integers that can be 100's
of MBs in length. What's the best way to do this?
IMHO std::deque is the best solution.
Should I simply create the array and let the OS deal with swapping?
What if the OS doesn't swap?
Or should I use a file as temporary space and fseek through it? Is there some
other better way?
I would only do the above if the deque throws a bad_alloc exception.
Aug 8 '06 #4

Daniel T. wrote:
In article <m3************@dsp.awid.com>, Randy Yates <ya***@ieee.org>
wrote:
Let's say I want to maintain an array of 16-bit integers that can be 100's
of MBs in length. What's the best way to do this?

IMHO std::deque is the best solution.
why using deque instead of vector?
Should I simply create the array and let the OS deal with swapping?

What if the OS doesn't swap?
Or should I use a file as temporary space and fseek through it? Is there some
other better way?

I would only do the above if the deque throws a bad_alloc exception.
Aug 9 '06 #5
Diego Martins wrote:
Daniel T. wrote:
>In article <m3************@dsp.awid.com>, Randy Yates
<ya***@ieee.orgwrote:
>>Let's say I want to maintain an array of 16-bit integers that can
be 100's of MBs in length. What's the best way to do this?

IMHO std::deque is the best solution.

why using deque instead of vector?
Insertions and removals from both ends are faster, my guess would be.
Also, implementation of deque is likely a "chunk"-based indirect array,
so it would be likely better suited for OSes that swap data... But
that's all not really related to C++.

V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
Aug 9 '06 #6
In article <11*********************@p79g2000cwp.googlegroups. com>,
"Diego Martins" <jo********@gmail.comwrote:
Daniel T. wrote:
In article <m3************@dsp.awid.com>, Randy Yates <ya***@ieee.org>
wrote:
Let's say I want to maintain an array of 16-bit integers that can be
100's
of MBs in length. What's the best way to do this?
IMHO std::deque is the best solution.

why using deque instead of vector?
I liked Victor's response, but my reason was different. I say use a
deque for very large blocks because the deque chunks it's data which
will likely make it easer for the memory manager to fit all the data in
if there is no paging of memory to disk. A deque is likely to cause
fewer fragmentation problems.
Aug 9 '06 #7

Diego Martins skrev:
Daniel T. wrote:
In article <m3************@dsp.awid.com>, Randy Yates <ya***@ieee.org>
wrote:
Let's say I want to maintain an array of 16-bit integers that can be 100's
of MBs in length. What's the best way to do this?
IMHO std::deque is the best solution.

why using deque instead of vector?
[snip]
Read Victor Bazarovs answer. Also, deque grows in a more gentle manner
.. without any reallocations. For that reason alone, some recommend
std::deque instead of std::vector. Actually, std::vector only has a
small constant speed advantage over std::deque (well - also contiguous
memory) so perhaps they are right?

Peter

Aug 9 '06 #8
peter koch wrote:
Diego Martins skrev:
Daniel T. wrote:
Randy Yates <ya***@ieee.orgwrote:
Let's say I want to maintain an array of 16-bit integers that can be 100's
of MBs in length. What's the best way to do this?
>
IMHO std::deque is the best solution.
why using deque instead of vector?
[snip]
[snip]
Actually, std::vector only has a
small constant speed advantage over std::deque (well - also contiguous
memory) so perhaps they are right?
Recognizing the OP from comp.dsp, I might speculate that he'd prefer
contiguous memory since most signal processing libraries don't accept
iterators. Without iterator support, the relevant section(s) of data
would need to be copied to contiguous memory and then possibly copied
back after processing. So really, I think Randy will need to be more
specific about how he's going to use the large buffers before we can
speculate accurately on what would be best.

Cheers! --M

Aug 10 '06 #9

"Randy Yates" <ya***@ieee.orgwrote:
This may be somewhat off-topic, but it sorta fits.

This is a C++ application that will be built using gcc and targeted
(via the wonderful wxWidgets library) for both Windoze and Linux.

Let's say I want to maintain an array of 16-bit integers that can be 100's
of MBs in length. What's the best way to do this? Should I simply
create the array and let the OS deal with swapping? Or should I
use a file as temporary space and fseek through it? Is there some
other better way?
I'd put that much data in a large number of small files, if possible,
rather than one huge file. Possibly keyed by value range. Then just
load one of the smaller files into memory at any one time, and close
the file when done with it for now.

If you do put a very large array (or container) of data in memory,
either declare it global, or "static" within a function, or dynamically
allocate it using new or malloc. I'd recommend against declaring it as
a simple local variable in a function, because that can cause stack
overflow:

void MyWeirdFunc()
{
static int Fred[100000000]; // probably ok, if you have 1 GB of RAM
int Jane[100000000]; // might overflow stack
// ... do stuff ...
return;
}

The "static" version also has the advantage of zeroing it's elements
when you program starts, unlike the non-static version.
--
Cheers,
Robbie Hatley
Tustin, CA, USA
lone wolf intj at pac bell dot net
(put "[usenet]" in subject to bypass spam filter)
home dot pac bell dot net slant earnur slant
Aug 16 '06 #10

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

Similar topics

20
by: Hemant Shah | last post by:
Folks, I am using DB2 UDB 8.2 on AIX 5.1. How large of a bufferpool can you create? I tried to create a 4GB bufferpool db2 complained that is cannot allocate enogth memory. I have 16GB on this...
5
by: David | last post by:
Hi all: I am processing a 3D bitmaps(essentially ~1024 2D bitmaps with a size of 1MB each). If I want read large amount of radom data from this series, how could I buffer the file to get...
0
by: Ramin Dalkouhi | last post by:
Hello, We are currently working on a serialization task which imports data into memory streams. At first, we had problems with a very high amount of data as the memory management of such memory...
1
by: lwickland | last post by:
Summary: System.Net.ScatterGatherBuffers.MemoryChuck allocates inordinately large bytes when sending large post data. The following application consumes inordinate quantities of memory. My code...
12
by: Sharon | last post by:
I’m wrote a small DLL that used the FreeImage.DLL (that can be found at http://www.codeproject.com/bitmap/graphicsuite.asp). I also wrote a small console application in C++ (unmanaged) that uses...
3
by: uday.das | last post by:
hi , I am not sure but I think it might be to avoid heap fragmentation due to several malloc calls. Are there any strong reason ? What are the other things that should take care when we implement...
3
by: douglas wittner | last post by:
morning all, can someone help me find the most efficient way of manipulating a large file. i need to replace special characters in a large file and multiple string.replace functions are causing...
28
by: bwaichu | last post by:
Is it generally better to set-up a buffer (fixed sized array) and read and write to that buffer even if it is larger than what is being written to it? Or is it better to allocate memory and...
7
by: iporter | last post by:
I use the code below to authorise the download of certain files. Thus, instead of linking to the file in a wwwroot directory, I link to this code with the filename as a parameter, and the script...
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:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.