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

buffer options

Hi all,

I want to make a buffer of structs but I don't want to have a static
size; I want it to be as dynamic as possible. Ordinarily, I would use a
list, but in this case I really want to avoid that. Right now, I'm thinking
something along the lines of:

MyStruct mystruct[1];

mystruct = (MyStruct*)LocalAlloc(sizeof(MyStruct)*MAX_BUF); //MS-specific
I know, sorry

But this still limits me to MAX_BUF items in the buffer at once. I was
also thinking about some kind of conditional re-sizing scheme but couldn't
think of a non-messy or fast enough solution along those lines.

Anyone have any suggestions?
--

Best wishes,
Allen

No SPAM in my email !!


Jul 19 '05 #1
5 3851

"Allen" <al************@att.SPAM.net> wrote in message
news:Fo*********************@bgtnsc04-news.ops.worldnet.att.net...
Hi all,

I want to make a buffer of structs but I don't want to have a static
size; I want it to be as dynamic as possible. Ordinarily, I would use a
list, but in this case I really want to avoid that. Right now, I'm thinking something along the lines of:

MyStruct mystruct[1];

mystruct = (MyStruct*)LocalAlloc(sizeof(MyStruct)*MAX_BUF); //MS-specific I know, sorry
This is not legal code, even with MS compiler. I think you meant

MyStruct* mystruct;
mystruct = (MyStruct*)LocalAlloc(sizeof(MyStruct)*MAX_BUF);

But this still limits me to MAX_BUF items in the buffer at once. I was also thinking about some kind of conditional re-sizing scheme but couldn't
think of a non-messy or fast enough solution along those lines.

Anyone have any suggestions?


Yes use a vector. Your situation is exactly what vector was designed for.

#include <vector>

std::vector<MyStruct> mystruct;

Add items to the vector using push_back (for instance)

MyStruct a_struct;
....
mystruct.push_back(a_struct);

the vector will grow dynamically. Or just call resize, if you have a
particular size in mind

mystruct.resize(100);

john
Jul 19 '05 #2

Allen <al************@att.SPAM.net> wrote in message
news:Fo*********************@bgtnsc04-news.ops.worldnet.att.net...
Hi all,

I want to make a buffer of structs but I don't want to have a static
size; I want it to be as dynamic as possible. Ordinarily, I would use a
list, but in this case I really want to avoid that. Right now, I'm thinking something along the lines of:

MyStruct mystruct[1];

mystruct = (MyStruct*)LocalAlloc(sizeof(MyStruct)*MAX_BUF); file://MS-specific I know, sorry

But this still limits me to MAX_BUF items in the buffer at once. I was also thinking about some kind of conditional re-sizing scheme but couldn't
think of a non-messy or fast enough solution along those lines.

Anyone have any suggestions?


std::vector<Mystruct> buffer;

-Mike

Jul 19 '05 #3
"Allen" <al************@att.SPAM.net> wrote in message
news:9T*********************@bgtnsc05-news.ops.worldnet.att.net...
Hi John, Samuele,

Thanks for the help. I've heard of vectors before but have never
bothered reading up on them. I would do so now, but my compiler is rather
old--I'm using MSVC++ 4.0--and doesn't seem to have them. I don't suppose
it's a simple matter of getting a copy of the .h and .lib files is it?

Allen,
I do not think getting the headers would be enough, since you will need a
compiler that supports templates. Maybe it's time for a compiler update...
if you are on a budget, it is worth checking out dev-cpp, it is free to
download and it supports most of the features you will need. Just search for
it using google.
HTH,
S. Armondi
Jul 19 '05 #4

"Allen" <al************@att.SPAM.net> wrote in message
news:9T*********************@bgtnsc05-news.ops.worldnet.att.net...
Hi John, Samuele,

Thanks for the help. I've heard of vectors before but have never
bothered reading up on them. I would do so now, but my compiler is rather
old--I'm using MSVC++ 4.0--and doesn't seem to have them. I don't suppose
it's a simple matter of getting a copy of the .h and .lib files is it?

Thanks and best wishes,
Allen


Try here http://www.stlport.org, not sure if it compiles for VC++ 4 though.
That is a really old compiler and the STL (of which vector is a part) makes
heavy use of templates. An old compiler might struggle.

john
Jul 19 '05 #5
>
Try here http://www.stlport.org, not sure if it compiles for VC++ 4 though. That is a really old compiler and the STL (of which vector is a part) makes heavy use of templates. An old compiler might struggle.


Just checked and it claims to support VC++ 4.

john
Jul 19 '05 #6

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

Similar topics

6
by: grunes | last post by:
I wish to fread a few thousand bytes at a time in turn from several very large files from a DVD data disk, under Redhat Fedora Linux. When this is done the DVD drive wastes a lot of time and...
1
by: Java Writer via .NET 247 | last post by:
Hey Mon!, This runs and gives me a 'iLen' of 4 but returns empty string. I am guessing this is the programmatic way to check Internet Explorer. {Tools}-{Internet Options)-(Settings...). Even...
5
by: nx-2000 | last post by:
I've got a very large C# forms app and now that its being used in bigger environments we're getting a steady stream of "why does it do this?" problems. The most nagging of which right now is that...
16
by: Jeff | last post by:
Im trying to memcpy a buffer from a filled in simple structure. When I memcpy and then print the resulting buffer, I see 7 locations that have junk before my data starts. My data structure is: ...
4
by: Greg Young | last post by:
Ok so I think everyone can agree that creating buffers on the fly in an async socket server is bad ... there is alot of literature available on the problems this will cause with the heap. I am...
331
by: Xah Lee | last post by:
http://xahlee.org/emacs/modernization.html ] The Modernization of Emacs ---------------------------------------- THE PROBLEM Emacs is a great editor. It is perhaps the most powerful and...
64
by: Philip Potter | last post by:
Hello clc, I have a buffer in a program which I write to. The buffer has write-only, unsigned-char-at-a-time access, and the amount of space required isn't known a priori. Therefore I want the...
2
by: chrisber | last post by:
using the unittest module in Python 2.3.5, I've written some test code that ends up with if __name__ == "__main__": unittest.main() Since I want to run this code in various environments, I'd...
36
by: James Harris | last post by:
Initial issue: read in an arbitrary-length piece of text. Perceived issue: handle variable-length data The code below is a suggestion for implementing a variable length buffer that could be used...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
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
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...

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.