473,785 Members | 3,134 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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.o rg % *A New World Record*, ELO
http://home.earthlink.net/~yatescr
Aug 8 '06 #1
9 3503
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.********@com Acast.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.o rg % '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.or gwrote:
>>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************ *********@p79g2 000cwp.googlegr oups.com>,
"Diego Martins" <jo********@gma il.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.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]
[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.org wrote:
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
8130
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 system. # db2 create bufferpool cfgbuffpool immediate size 1048576 pagesize 4096 SQL20189W The buffer pool operation (CREATE/ALTER) will not take effect until
5
1929
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 optimized performance? With WinXP pro/512MB memories and no other big programmes running at the same time. Cheers
0
1284
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 streams is always multiplying the required memory buffer size by two. We are now "guessing" the required amount and are setting the capacity properly. The next Problem (which is the one I'am talking about) is the ToArray() method of that memory...
1
4013
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 does not explicitly allocate memory in a loop nor does it explicitly allocate large blocks of memory. Yet, the application’s memory footprint will grow as large as 370 MB. Rarely will it run to completion; usually, it throws an out of memory...
12
6191
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 the DLL above. Now the application, together with the above DLL’s is successfully loading a TIF image file (62992 x 113386 Pixels, Huffman RLE compression, 3200 x 3200 DPI resolution, binary colored (1 Bit Per Pixel), file on disk size 43.08...
3
1479
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 a memory manager , like i) garabage collector kind of thing , ii) Safe Free of pointer in wrapper of Free functions etc . Thanks Uday
3
1656
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 memory errors. doug
28
3880
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 realloc it for the size of the what is being written each time? In other words, what is the decision factor between deciding to use a fixed size buffer or allocating memory space and reallocing the size? I don't think the code below is optimal...
7
9900
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 streams the file if the user is authorised. This has worked fine on PDFs, DOCs, XLS, etc. until today, and 18MB file presents the error message 'format error: not a pdf or corrupt'. Is there a file size limit, or a default that needs...
0
9643
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10319
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10087
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9947
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
6737
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5511
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4046
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3645
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2877
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.