Thread: space efficiency

  1. #1
    Registered User
    Join Date
    Sep 2002

    space efficiency

    I was wondering what the most space efficient way to store strings was? Can you only put them in an array or is there something better?

  2. #2
    Confused Magos's Avatar
    Join Date
    Sep 2001
    Well, obviously this isn't so efficient:
    char String[1024] = "Hello world!";

    It's a waste of 1011 bytes...

    Instead use:
    char String[] = "Hello world!";

    char* String = "Hello world!";

    Or use dynamic allocation if you don't know the strings length.

    Give a man a fish and you feed him for a day.
    Teach a man to fish and you feed him for a lifetime.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Out of space when compiling kernel
    By NuNn in forum Linux Programming
    Replies: 3
    Last Post: 04-01-2009, 02:43 PM
  2. Calculating space efficiency using sizeof()
    By markcls in forum C Programming
    Replies: 6
    Last Post: 05-19-2007, 05:25 AM
  3. disk space mysteriously gone
    By evader in forum C++ Programming
    Replies: 4
    Last Post: 01-21-2004, 01:30 PM
  4. someone who is good at finding and fixing bugs?
    By elfjuice in forum C++ Programming
    Replies: 8
    Last Post: 06-07-2002, 03:59 PM