Thread: Stuck halfway through a function

  1. #16
    Registered User
    Join Date
    May 2008
    Posts
    28
    Thanks.

    Is it considered bad form to just brute force allocate enough memory in the first place (eg, 80 chars) ?

  2. #17
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    No, not really (although too much is usually a bad thing(TM)). Memory is plenty and brute force allocation is faster. If you think it's enough, then most of the times, it's fine.
    But if you don't know that it may be enough, dynamic may be better.
    But in C, it's better to brute force to get rid of complexity of having to call free. In a big application, it can be difficult to know where to free the memory.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  3. #18
    Technical Lead QuantumPete's Avatar
    Join Date
    Aug 2007
    Location
    London, UK
    Posts
    894
    This reminds of a function I saw once, which had to assemble a string from some input parameters and then write it out to a file or something. Because the code had to be fast, the programmer created a 100 char array to assemble the string in. The code then checked whether the final string would be longer than 100 chars and if so, would allocate memory on the heap instead. The final string didn't have to be passed anywhere though, so there were no free issues.
    Not that I condone that kind of thing

    QuantumPete
    "No-one else has reported this problem, you're either crazy or a liar" - Dogbert Technical Support
    "Have you tried turning it off and on again?" - The IT Crowd

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Beginner Needs help in Dev-C++
    By Korrupt Lawz in forum C++ Programming
    Replies: 20
    Last Post: 09-28-2010, 01:17 AM
  2. dllimport function not allowed
    By steve1_rm in forum C++ Programming
    Replies: 5
    Last Post: 03-11-2008, 03:33 AM
  3. doubt in c parser coding
    By akshara.sinha in forum C Programming
    Replies: 4
    Last Post: 12-23-2007, 01:49 PM
  4. Problem with Visual C++ Object-Oriented Programming Book.
    By GameGenie in forum C++ Programming
    Replies: 9
    Last Post: 08-29-2005, 11:21 PM
  5. c++ linking problem for x11
    By kron in forum Linux Programming
    Replies: 1
    Last Post: 11-19-2004, 10:18 AM