Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Apr 21st, 2006, 11:39 AM   #1
hbe02
Hobbyist Programmer
 
hbe02's Avatar
 
Join Date: Mar 2006
Location: Lebanon
Posts: 148
Rep Power: 3 hbe02 is on a distinguished road
Memory problem

Im trying to read a char * from an input text file.
char* video=new char[10000]; 
ifstream getvid (file);
getvid>>video;
getvid.close();
the input form the text file is a bitstream of 1's and 0's.
if the size of the bitstream was lets say 50. there would be no problem wiht the code. but if i initialize :
Quote:
char* video=new char[10];
where 10 < 50 . then when the program terminates. an error is generated. im guessing because the computer failed to delete the pointers pointing to the last 40 bits.
how do i avoid this problem if i dont want to give a very large number for initializing the file video.
lets say the bitstream was as big as a megabyte. and i want to read it into video, there is a limit to how big the constant in char[constant] is. so whats is the solution.
hbe02 is offline   Reply With Quote
Old Apr 21st, 2006, 11:57 AM   #2
Cache
Hobbyist
 
Join Date: Sep 2005
Posts: 266
Rep Power: 4 Cache is on a distinguished road
Open the stream in binary mode, and use tellg() to first get the size of the file.
Cache is offline   Reply With Quote
Old Apr 21st, 2006, 4:55 PM   #3
hbe02
Hobbyist Programmer
 
hbe02's Avatar
 
Join Date: Mar 2006
Location: Lebanon
Posts: 148
Rep Power: 3 hbe02 is on a distinguished road
were can i read about binary mode, i know nothing about it..?
hbe02 is offline   Reply With Quote
Old Apr 21st, 2006, 5:12 PM   #4
Twilight
Programmer
 
Join Date: Apr 2006
Location: Calgary, Alberta
Posts: 67
Rep Power: 3 Twilight is on a distinguished road
Just google "Binary I/O C++" and there should be a crap load of pages on the subject
Twilight is offline   Reply With Quote
Old Apr 21st, 2006, 6:14 PM   #5
DaWei
Resident Grouch
 
DaWei's Avatar
 
Join Date: Jun 2005
Posts: 6,453
Rep Power: 10 DaWei is on a distinguished road
Google "binary I/O"?? All I/O is binary I/O. It's all a stream of 1s and 0s. Text mode, which is strictly a windows thangy, has to do with adding extra binary characters that you wouldn't normally expect to be added. They play some hob with seek and tell operations. Text is just binary I/O that is expected to be interpreted in some 'different' way, nothing to do with the mode, per se. That is, if it's ASCII, 61 is interpreted as lower-case 'a', rather than decimal 61. 'S'all the same as far as the I/O is concerned, it doesn't know or care. Once you realize this and don't let it buffalo you, you shouldn't have any problems using any of the mechanisms.
__________________
Abstraction doesn't make it impossible to write bad code; it makes it possible to write superior code.
Contributor's Corner: Grumpy on C++ Exceptions DaWei on Pointers
DaWei is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

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 On
HTML code is Off
Forum Jump




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 1:56 AM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC