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

How to provide buffer size dynamically.

151 100+
Hi,

Normally when we read a file we need to provide buffer size. How it can be provided dynamically to save the space and time.


Regards
Apr 26 '10 #1
4 2484
Banfa
9,065 Expert Mod 8TB
That problem description is too vague for us to answer clearly. That is people may answer but because your description is so vague there is a high probability that they will misinterpret you and give you the answer to a different question to the one you are trying to ask.

It is common for small to medium size files to get the size of the file first and allocate a buffer large enough to hold the entire file before reading it in.

Reading a line at a time into a string in C++ you don't need to know the size of the line the library sizes the string to the required size.
Apr 26 '10 #2
Man4ish
151 100+
Thanks for our answer which is appropriate but using string class will be slower. Is there any way to allocate the buffer size dynamically?
Apr 26 '10 #3
Banfa
9,065 Expert Mod 8TB
Use new (or malloc if it is C)
Apr 26 '10 #4
weaknessforcats
9,208 Expert Mod 8TB
Do a seek to the end of the file followed by a tell. That will get you the number of bytes in the file. Allocate that amount.
Apr 27 '10 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

5
by: Allen | last post by:
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...
1
by: inkapyrite | last post by:
Hi all. I'm using ifstream to read from a named pipe but i've encountered an annoying problem. For some reason, the program blocks on reading an ifstream's internal buffer that's only half-filled....
2
by: derek.google | last post by:
I have an application that's crashing because of an alignment problem, and this is the smallest program that demonstrates what's happening: int main() { struct Message { unsigned short size;...
2
by: William Stacey | last post by:
Working with implementing a circular buffer for a producer/consumer deal. Have not done one in a while. The following seems to work. However, I remember and have seen other implementation that...
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...
43
by: Frodo Baggins | last post by:
Hi all, We are using strcpy to copy strings in our app. This gave us problems when the destination buffer is not large enough. As a workaround, we wanted to replace calls to strcpy with strncpy....
0
by: Jack | last post by:
Hi, I do a webrequest and it returns some text data in a stream. I want to put this tyext data into a string. I've got it working just fine, but I have to put the text data into into a...
4
by: Jack | last post by:
Hi, I do a webrequest and it returns some text data in a stream. I want to put this text data into a string. I've got it working just fine, but I have to put the text data into into a...
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: vijayrvs | last post by:
SearchCrawler.java The program search crawler used to search the files from the website. From the following program i got 7 compiler error. can any body clarify it and provide me solution. ...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
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: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
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...

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.