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

Create filke with a specified dimension

Hi!

I'm writing an application that receives data from internet. I usually
receive big files, few hundred MB to Gb and the packets I receive could
be not in a correct order. I though I could send a packet that specify
the lenght of the file before any other packet. The receiver creates
this file, with the specified dimension and then using ofstream's write
and seekp I would write the packets in the correct position.

My problem is, how can I create a file with a specific dimension? Do I
have to use something like

while(lenght < the_lenght_i_want)
write(new char[1000], 1000)

???
Then close the file and open it every time I receive a packet? I can't
use a buffer, at least not a buffer that contains the whole file!
Any suggestion?

Thank you!

Sep 7 '06 #1
6 1705
Paolo wrote:
I'm writing an application that receives data from internet. I
usually receive big files, few hundred MB to Gb and the packets I
receive could be not in a correct order.
Why don't you use TCP?
Sep 7 '06 #2
It's a multicast protocol...

Sep 7 '06 #3
Paolo wrote:
Hi!

I'm writing an application that receives data from internet. I usually
receive big files, few hundred MB to Gb and the packets I receive could
be not in a correct order. I though I could send a packet that specify
the lenght of the file before any other packet. The receiver creates
this file, with the specified dimension and then using ofstream's write
and seekp I would write the packets in the correct position.

My problem is, how can I create a file with a specific dimension? Do I
have to use something like

while(lenght < the_lenght_i_want)
write(new char[1000], 1000)
This allocates the 1000 chars everytime you write it
to the file, why not allocate it once, _before_ you write
to the file. Do you come from a Java background? :)
Any suggestion?
Try
1) opening the file
2) lseek()ing to the position you want minus one byte
3) write one byte.

I have no idea if its portable or if it works at all,
but it's worth a try. Your file will initially contain
garbage, but the method you proposed has the same
drawback and is way slower.

HTH,
- J.
Sep 7 '06 #4
Thank youn for your reply!
I'll try that!

PS: That was just a piece of code, I wouldn't write something like
that. Another drawback would be that I don't free allocated memory, so
with a 1 Gb file I would halt or crash the system!!
Jacek Dziedzic ha scritto:
Paolo wrote:
Hi!

I'm writing an application that receives data from internet. I usually
receive big files, few hundred MB to Gb and the packets I receive could
be not in a correct order. I though I could send a packet that specify
the lenght of the file before any other packet. The receiver creates
this file, with the specified dimension and then using ofstream's write
and seekp I would write the packets in the correct position.

My problem is, how can I create a file with a specific dimension? Do I
have to use something like

while(lenght < the_lenght_i_want)
write(new char[1000], 1000)

This allocates the 1000 chars everytime you write it
to the file, why not allocate it once, _before_ you write
to the file. Do you come from a Java background? :)
Any suggestion?

Try
1) opening the file
2) lseek()ing to the position you want minus one byte
3) write one byte.

I have no idea if its portable or if it works at all,
but it's worth a try. Your file will initially contain
garbage, but the method you proposed has the same
drawback and is way slower.

HTH,
- J.
Sep 8 '06 #5

Paolo ha scritto:
Thank youn for your reply!
I'll try that!

PS: That was just a piece of code, I wouldn't write something like
that. Another drawback would be that I don't free allocated memory, so
with a 1 Gb file I would halt or crash the system!!
Jacek Dziedzic ha scritto:
Paolo wrote:
Hi!
>
I'm writing an application that receives data from internet. I usually
receive big files, few hundred MB to Gb and the packets I receive could
be not in a correct order. I though I could send a packet that specify
the lenght of the file before any other packet. The receiver creates
this file, with the specified dimension and then using ofstream's write
and seekp I would write the packets in the correct position.
>
My problem is, how can I create a file with a specific dimension? Do I
have to use something like
>
while(lenght < the_lenght_i_want)
write(new char[1000], 1000)
This allocates the 1000 chars everytime you write it
to the file, why not allocate it once, _before_ you write
to the file. Do you come from a Java background? :)
Any suggestion?
Try
1) opening the file
2) lseek()ing to the position you want minus one byte
3) write one byte.

I have no idea if its portable or if it works at all,
but it's worth a try. Your file will initially contain
garbage, but the method you proposed has the same
drawback and is way slower.

HTH,
- J.
Sorry Brian, I got it now!

Sep 8 '06 #6
Paolo wrote:
Hi!

I'm writing an application that receives data from internet. I usually
receive big files, few hundred MB to Gb and the packets I receive could
be not in a correct order. I though I could send a packet that specify
the lenght of the file before any other packet. The receiver creates
this file, with the specified dimension and then using ofstream's write
and seekp I would write the packets in the correct position.

My problem is, how can I create a file with a specific dimension? Do I
have to use something like

while(lenght < the_lenght_i_want)
write(new char[1000], 1000)
BTW, use a named constant, rather than magic numbers:
const unsigned int BUFFER_SIZE = 1000;
//...
buffer = new unsigned char[BUFFER_SIZE];
//...
write(buffer, BUFFER_SIZE);
>
???
Then close the file and open it every time I receive a packet? I can't
use a buffer, at least not a buffer that contains the whole file!
Any suggestion?

Thank you!
The old school method is to write to the file, then sort and
analyze later. You can flush the file after receiving each
packet. BTW, files don't have dimensions.

Other tricks involve "double buffering" (hint use Google).

--
Thomas Matthews

C++ newsgroup welcome message:
http://www.slack.net/~shiva/welcome.txt
C++ Faq: http://www.parashift.com/c++-faq-lite
C Faq: http://www.eskimo.com/~scs/c-faq/top.html
alt.comp.lang.learn.c-c++ faq:
http://www.comeaucomputing.com/learn/faq/
Other sites:
http://www.josuttis.com -- C++ STL Library book
http://www.sgi.com/tech/stl -- Standard Template Library

Sep 9 '06 #7

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

Similar topics

3
by: Biswajit Barik | last post by:
Hi All, I want to create a cube using MSSQL2000 i dont know any thing how to create and what is parameter required so if any body help me i will be thankfull to him/her.For information : i have 4...
1
by: Lo?c Henry-Gr?ard | last post by:
Hi, I'm using a homebrew, lightweight version of SIunits, the physical dimension checker. For example I define types such as m (meters), s (seconds) and mps (meters per second) in namespace SI...
7
by: dog | last post by:
I've seen plenty of articles on this topic but none of them have been able to solve my problem. I am working with an Access 97 database on an NT4.0 machine, which has many Access reports. I...
4
by: Bill Sun | last post by:
Hi, All I have a conventional question, How to create a 3 dimension array by C language. I see some declare like this: int *** array; int value; array = create3Darray(m,n,l);
6
by: pallavi27 | last post by:
HI, i want to declare an array that should accept any size given by the user.how to declare such array?please explain me with the help of a code..it should display on the screen "enter the no of...
14
by: Lee | last post by:
I have a xml file, here is sample part: <?xml version="1.0" encoding="UTF-8"?> <ProducsList> <Product id="1"> <SpecList> <Spec> <SpecLabel>Height</SpecLabel> <SpecValue>10</SpecValue>...
5
by: Lee | last post by:
I have a xml file, here is sample part: <?xml version="1.0" encoding="UTF-8"?> <ProducsList> <Product id="1"> <SpecList> <Spec> <SpecLabel>Height</SpecLabel> <SpecValue>10</SpecValue>...
3
by: marishka88 | last post by:
I'm using Turbo C++ and I'm trying to convert letters to specified letters using single-dimension arrays. Lets say I enter the name MATT into the program and it'll cipher the name to HYKR. How can...
152
by: vippstar | last post by:
The subject might be misleading. Regardless, is this code valid: #include <stdio.h> void f(double *p, size_t size) { while(size--) printf("%f\n", *p++); } int main(void) { double array = { {...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
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: 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
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...

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.