473,767 Members | 8,004 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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_wa nt)
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 1720
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_wa nt)
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_wa nt)
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_wa nt)
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_wa nt)
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.l earn.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
27919
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 tables custdetailtable which contain all about a customer as per example customer ID,name,add,CUSTOMERID IS PRIMARYKEY, Proddetail table which contain all about a product mean productcode,productname,productvalue,dman (dateof manufacture),dexp...
1
1628
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 and I have all the overloadings of operator* such as SI::m operator* (SI::s, SI::mps) { ... }
7
8869
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 want my users to be able to select a report, click on a command button on a form, which will then automatically create the report as a pdf file and save it to the user's machine. I am using Adobe Acrobat (5.0 I think) and have Adobe Distiller as a
4
4337
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
2150
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 rows" and" enter the no of columns" and it should accept any size specified by the user.
14
5157
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> <SpecCat>Dimension</SpecCat> </Spec>
5
3730
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> <SpecCat>Dimension</SpecCat> </Spec>
3
1571
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 I achieve this? Thanks.
152
9887
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 = { { 3.14 }, { 42.6 } }; f((double *)array, sizeof array / sizeof **array); return 0;
0
9575
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
9407
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
9960
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
8840
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7384
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5425
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3931
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
3534
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2808
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.