Thread: Dynamic Memory Allocation for fstream (binary)

  1. #1
    Registered User
    Join Date
    Nov 2001
    Posts
    1,348

    Dynamic Memory Allocation for fstream (binary)

    Hi,

    I am having problem allocating memory to read and write in binary mode.

    The program I am working on reads data from a file and write the data back to a second file. Both process are done through binary.

    I set it to dynamically allocate memory based on the size of the file or size of data. However, I am encountering a weird problem. It seems I can read from any text file and write the same data to a second file. On the other hand, I the program crashes when I read data from binary file such as anything from jpeg to an executable. The program seems to crashs right before the memory allocation. I put a check sign (cout "check") right before and right after the allocation. The program seems to crash there.

    Is there a particular rule that I missed when reading and writing binary files (anything other than text)? Note I save the data from the file to memory through a dynamically allocated variable. Do I need to use a string?

    Kuphryn

  2. #2
    of Zen Hall zen's Avatar
    Join Date
    Aug 2001
    Posts
    1,007
    You'll have to post some code. Reading and writing in binary should be the same regardless of the type of file.
    zen

  3. #3
    Registered User
    Join Date
    Nov 2001
    Posts
    1,348
    Okay. Thanks.

    I finally figure out the problem. The problem has to do with mathematics, not C++ itself.

    I hear experience programmers say time and time that programming is heavy on mathematics. I got my first-hand experience with this program I am working on. It is done! I am very relieve.

    Thanks everyone.

    Kuphryn

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. what is dynamic memory allocation
    By dbzx in forum C Programming
    Replies: 7
    Last Post: 06-08-2009, 08:11 AM
  2. dynamic memory allocation on demand
    By oilrg in forum C Programming
    Replies: 5
    Last Post: 12-02-2007, 02:59 AM
  3. Dynamic Memory Allocation
    By oranges in forum C++ Programming
    Replies: 3
    Last Post: 11-28-2006, 07:50 AM
  4. dynamic memory allocation w/o new
    By bd43274 in forum C++ Programming
    Replies: 11
    Last Post: 02-15-2006, 02:12 AM
  5. Binary Search Trees Part III
    By Prelude in forum A Brief History of Cprogramming.com
    Replies: 16
    Last Post: 10-02-2004, 03:00 PM