LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
Search this Thread
Old 08-07-2007, 01:12 PM   #1
tntcoder
Member
 
Registered: Sep 2003
Distribution: Arch
Posts: 89

Rep: Reputation: 15
File Space Allocation + Writing (C++)


Hi,

My program takes a series of encoded file segments, and decodes each segment and writes it to the output file.

I am trying to approach this as follows:

I know the size of the output file in bytes so i pre-allocate the space for it and fill it with NULL bytes using the linux truncate function, I do this incase one of segments is missing i just want null bytes in its place with the other segments around the missing block.

I also know the position (start and end) in bytes where each decoded segment needs to go in the output file, so using ofstream i am 'attempting' to use seekp to set the file pointer at the position on the truncated file and write my decoded segment out.

The problem is that if I don't open the file in append mode (ios::app) then it automatically overwrites the output file contents, so all previous written segments are deleted. And if i use append mode, then seekp doesn't seem to work, and after the truncate() is performed, the segments just get appended onto the end of the file instead of overwriting the null bytes at the position specified.

Now for some code:

Code:
ofstream ostr(ofile.c_str(), ios::app);  // Open output file in append mode

...

truncate(ofile.c_str(), file_size_in_bytes); // Fill the file to specified size with NULL bytes 

...

ostr.seekp(begin_bytes - 1); // Move to segment start position in the file

...

My decoding/file output

//Clean up
ostr.close();

Anyone know where im going wrong?
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Hard Drive space allocation Sheesh Suse/Novell 15 02-13-2006 12:57 PM
kernel memory + slabinfo.. + possible reasons for kernel space allocation failures!! premenjit Linux - Software 1 09-28-2004 04:13 AM
Space Allocation for File Systems majicrobot Linux - Hardware 1 09-20-2004 05:06 PM
dynamic allocation of memory in kernel space appas Programming 1 08-04-2004 06:32 AM
Large tar file taking huge disk space in ext3 file system pcwulf Linux - General 2 10-20-2003 07:45 AM


All times are GMT -5. The time now is 12:34 AM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration