Thread: Memory problems (?)

  1. #1
    Chad Johnson
    Join Date
    May 2004

    Memory problems (?)

    (this is actually a c++ program, but the C++ board obviously deals more with gui stuff)

    I am writing a program where I have tree structure, and I have a private char array

    char binPath [256];

    and whenever I run the program, it crashes. when I comment out the declaration line, it works fine. Why?

    I have tried using a pointer, and didn't have very much more luck.

    My program uses the huffman compression to compress a text file. I want to store a [binary] path to each leaf in the tree. I wanted to store this path in a char array (or pointer), with 1's and 0's, but is there a more memory efficient way?

  2. #2
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    This should be on the C++ board. Doubtless a moderator will move it over there for you, so don't cross-post. Your error is likely in another spot in your program, and what you're seeing is behavior that's a side effect of it. I suspect you're blowing past an array, or using an uninitialized pointer or what not, which happend to be trying to use your protected array because that's where it just happens to be accessing when that's in.

    In the future, consider posting more of your code. You'll also want to consider using a stripped down version of your class to test out the situation. Example, if you have a class that has some twenty member functions, and they all work, but one doesn't, try creating a class just for that function, and once you've got that fixed, then integrate the function into the big class again. (Once you know your logic and code is correct on a small scale.)

    Hope is the first step on the road to disappointment.

  3. #3
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    The edge of the known universe
    > (this is actually a c++ program, but the C++ board obviously deals more with gui stuff)
    No, it should be on the C++ board
    Overty GUI stuff gets moved to the windows board, if that is the kind of GUI it refers to
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Memory allocation/reallocation
    By magda3227 in forum C Programming
    Replies: 10
    Last Post: 07-04-2008, 03:27 PM
  2. Memory problem with Borland C 3.1
    By AZ1699 in forum C Programming
    Replies: 16
    Last Post: 11-16-2007, 11:22 AM
  3. Weird memory problems (MS-VC++)
    By mikahell in forum C++ Programming
    Replies: 2
    Last Post: 06-11-2006, 08:01 AM
  4. Shared Memory - shmget questions
    By hendler in forum C Programming
    Replies: 1
    Last Post: 11-29-2005, 02:15 AM
  5. stl::vector problems (memory?)
    By aker_y3k in forum C++ Programming
    Replies: 3
    Last Post: 04-15-2003, 11:21 AM