Useful Function or Junk?
-
this is a little something I wrote because I had idle hands a little bit ago and needed something to do. Excuse the, how should I say, rather droll nature of the function name, but that happened to be the commercial airing at the time I was working on another project, hence the naming. I figured this might have some use so I went ahead and posted it, however simplistic it may seem.
/////////////////////////////////////////////
//
// Liquid Plumber: Buffer Cleanup Function
//
// function takes 1 parameter which is the
// variable name of the char array to act on.
// this is just a simple wrapper around the
// memset function to allow "hands-free" use
//
/////////////////////////////////////////////void LiquidPlumber( char * szBufferName )
{
memset(szBufferName, 0, sizeof(szBufferName));
}My question is this, is this a useful function by way of that facts that it brings the amount of work down to just specifying the variable name to act on, or is it simpler and more "syntax" correct to simply call memset? The function handles calculating the size of the buffer internally and also specifies a zero value as the character to fill the buffer with. IMHO, I think it's easier to use this function as it saves repeated calls to memset in programs where multiple buffers are used, and in most cases, filling the buffer with a zero value, especially if it's in a program like a server app thats using a buffer as temp storage for commands recieved from a tcp/ip port. It would be easier to call this than to have to manually code the values. Comments / Suggestions Appreciated.
It's good to see kids turning their minds to wholesum activities such as programming, instead of wasting their lives in the hedonistic disciplines of Sex, Drugs, & Rock & Roll... or Sex with Drugs, or Sex with Rocks while Rolling in Drugs, or whatever new-fangled perversions you little monsters have thought up now... [Shog9 on Kid Programmers]
It's very convenient to have a function that takes less arguments than memset. But since it does not do the job (note that sizeof(char*) is always 4 under Win32, no matter what is the length of the actual string), then you could skip the first argument as well: void OptimizedLiquidPlumber(void) { // Nothing to do, still almost as good as the original LiquidPlumber } ;P Vagif Abilov MCP (Visual C++) Oslo, Norway
-
this is a little something I wrote because I had idle hands a little bit ago and needed something to do. Excuse the, how should I say, rather droll nature of the function name, but that happened to be the commercial airing at the time I was working on another project, hence the naming. I figured this might have some use so I went ahead and posted it, however simplistic it may seem.
/////////////////////////////////////////////
//
// Liquid Plumber: Buffer Cleanup Function
//
// function takes 1 parameter which is the
// variable name of the char array to act on.
// this is just a simple wrapper around the
// memset function to allow "hands-free" use
//
/////////////////////////////////////////////void LiquidPlumber( char * szBufferName )
{
memset(szBufferName, 0, sizeof(szBufferName));
}My question is this, is this a useful function by way of that facts that it brings the amount of work down to just specifying the variable name to act on, or is it simpler and more "syntax" correct to simply call memset? The function handles calculating the size of the buffer internally and also specifies a zero value as the character to fill the buffer with. IMHO, I think it's easier to use this function as it saves repeated calls to memset in programs where multiple buffers are used, and in most cases, filling the buffer with a zero value, especially if it's in a program like a server app thats using a buffer as temp storage for commands recieved from a tcp/ip port. It would be easier to call this than to have to manually code the values. Comments / Suggestions Appreciated.
It's good to see kids turning their minds to wholesum activities such as programming, instead of wasting their lives in the hedonistic disciplines of Sex, Drugs, & Rock & Roll... or Sex with Drugs, or Sex with Rocks while Rolling in Drugs, or whatever new-fangled perversions you little monsters have thought up now... [Shog9 on Kid Programmers]
Use the following and be done with it: *szBufferName = '\0'; I see code all the time when folks zero out strings for no reason. They waste processor time and their own. I had a friend who told me once that he worked with a contractor that zero'ed out every string by using a for-loop. Clever...