> > >They could, of course, just call ParamCStringValue() and then copy
> > >the memory it points to, which would seem to eliminate the need for
> > >the Copy... functions altogether.
> I take it you think that the data will be a null terminated string.
The ...CString... functions are intended to work with null
terminated strings. We would probably also want corresponding
...Data... functions to work with binary data.
> More likely(to support binary data) you would have to do a copy
anyway like:
>
> int myFlag;
> unsigned int len = GetParamLength( param );
> char * paramPtr = (char *)malloc(len+1);
> memcpy(paramptr,GetParamData(),len);
> paramptr[len] = '\0';
> myFlag = strcmp(paramPtr, "yes");
> free(paramPtr);
>
> If you need to access the data without copying you could use strncmp
> instead:
> strncmp(GetParamData(), "yes", GetParamLength(param));
Exactly. Copy it if you need to, but it probably won't be necessary
for simple comparisons or even more complex operations like
searching and parsing, as long as you don't need to change the data
in place or keep it for an extended time.
Doug