Intensive String functions

This is a discussion on Intensive String functions within the Tech Board forums, part of the Community Boards category; Hello All, Not as expected, this post is not help request I am developing an assembler. And while I am ...

  1. #1
    Registered User
    Join Date
    Mar 2011
    Posts
    27

    Intensive String functions

    Hello All,

    Not as expected, this post is not help request
    I am developing an assembler. And while I am developing this program, I found myself creating generic string functions which I ound very useful. I want to share these functions .. where should I post them?

    functions I developed till now:
    Code:
    char ** addToString(char ** stringArray, char * string, unsigned int numberOfLines)
    // which adds a string in an array of strings
    Code:
    char * readLine(FILE * stream)
    // which returns a line from a file
    Code:
    char * readLine(FILE * stream, unsigned int lineNum)
    // which returns the line requested by its number. Note: this function needs the function above.
    Code:
    char * getstring()
    // returns a string entered by the user. It's like Console.ReadLine() in C# or raw_input() in Python.
    Code:
    char * append(char * mainString, char * appendedString)
    // appends a string to another string.

    all functions above automatically handles the memory. That is, all you have to worry about is the name of the variable you create and nothing more
    examples:
    Code:
    char * input = getstring();
    // input will hold the input string from the user
    Code:
    char * line = readLine(filePointer);
    // line will hold a line read from the file. if EOF reached, "EOF" is returned.
    Code:
    char * newString = append("the", " new");
    // newString will hold the string "the new"

  2. #2
    Algorithm Dissector iMalc's Avatar
    Join Date
    Dec 2005
    Location
    New Zealand
    Posts
    6,299
    One approach would be to make a little website of your own and put your files on there. Many ISPs have free web hosting, though I'm sure you can find other options online as well.
    Add a link to the site in your signature, for example, and let google and its users do the rest.

    Use asserts. Code defensively, making sure that users who do silly things like passing in NULL pointers don't end up getting a crash a lot further down the line.

    Start getting into unit testing. As you make changes and fixes, you need to run tests you have saved to ensure that the existing bits still work correctly.

    Install multiple compilers and try to get your code to compile against each of them. Many users will not be running the same compiler as you and you'd be surprised how easily code that looks perfectly good will throw up tons of errors on a different compiler.

    Get a feel for who your target audience is, what their skill level is etc. Try to make sure that you have something to offer that has some advantage over whatever else similar is out there.

    Make sure you provide a means of contacting you (i.e email address), and make it clear what kinds of restrictions you want to place on the code, whether it's public domain, GPL etc.

    Last but not least, make sure you provide adequate instructions or documentation on how to use things. E.g. about freeing memory allocated by your code.
    My homepage
    Advice: Take only as directed - If symptoms persist, please see your debugger

    Linus Torvalds: "But it clearly is the only right way. The fact that everybody else does it some other way only means that they are wrong"

  3. #3
    Registered User
    Join Date
    Jun 2005
    Posts
    6,243
    Quote Originally Posted by iMalc View Post
    Last but not least, make sure you provide adequate instructions or documentation on how to use things. E.g. about freeing memory allocated by your code.
    This advice is highly relevant in this case, given the comment that "all functions above automatically handles the memory". That makes it a fair bet that the functions are either using static memory or (more likely, I suspect) they are employing dynamic memory allocation. Either way, using these functions imposes specific constraints on what the caller is allowed to do. If the functions are using any static memory, then they cannot be used safely in a reentrant manner (such as two calls within one statement). If the functions are doing dynamic memory allocation, the caller must keep track of the returned pointers, and release the memory when done.
    Right 98% of the time, and don't care about the other 3%.

  4. #4
    Super Moderator VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,596
    The OP might want to read this if this code is going to be in a dll.
    DLLs and Dynamic Memory Allocation

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Question about functions of string vs char string
    By Robertjh12 in forum C++ Programming
    Replies: 2
    Last Post: 07-07-2011, 03:13 AM
  2. Replies: 0
    Last Post: 03-26-2010, 08:15 AM
  3. send and recv are cpu intensive?
    By Rune Hunter in forum Networking/Device Communication
    Replies: 14
    Last Post: 09-04-2007, 09:24 AM
  4. DirectX always this intensive?
    By mrafcho001 in forum Game Programming
    Replies: 11
    Last Post: 01-19-2006, 03:30 PM

Tags for this Thread


1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21