[Freeciv-Dev] Re: Split patch (was Re: [RFC PATCH] init_techs)
[Top] [All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
At 09:52 AM 01/09/28 +0200, Raimar Falke wrote:
>On Fri, Sep 28, 2001 at 12:00:07AM -0400, Ross W. Wetmore wrote:
>> I like your statement of what you claim to be agreeing to followed
>> by what you actually want to do in practice.
>>
>> Why on earth would you handle the same buffer contents 3 times with
>> all those allocation and free calls when you could do it once and
>> let the caller deal with at most one extra copy depending on whether
>> the original buffer or the results needed to be preserved.
>>
>> But most of the time I would expect that no extra copies were required
>> in the caller algorithms.
>
>> split should treat the buffer it was handed as working memory, return
>> pointers into the parsed string elements, and let the caller deal with
>> ALL memory issues.
>
>Ok since there is so much resistance: we implement the strdup/free in
>split if it turns out that every caller of split will copy the string
>because it is needed later. Ok?
A better way is to just implement split to take a buffer and do its
splitting thing in a reasonable and efficient manner.
If everyone needs a strduped version of the original buffer, then do
a wrapper function of the form
int split_that_copies_and_recopies_memory_to_please_raimar(
const char *const toks, const char *const string,
char *items[], int max_items)
{
int ret;
char *buffer = strdup(string);
ret = split(toks, buffer, items, max_items);
/* do whatever mystrlcopy or items strduping you want to generate
* memory allocations in items[] that the caller will have to free
* but invariably won't, generating hard to track memory leaks.
*
* However, most callers will probably want to implement just
* one of these extra copies, not both and hence will probably
* find this routine a useless performance inhibitor.
*/
free(buffer);
return ret;
}
At least this way, people won't be forced to use your VERY bad programming
practices if they don't want to.
>There just are no memory leaks possible.
You weren't listening again ...
> Raimar
>--
> email: rf13@xxxxxxxxxxxxxxxxx
> "From what I am reading Win98 and NT5.0 will be getting rid of all that
> crap anyway. Seems that Microsoft has invented something called TCP/IP and
> another really revolutionary concept called DNS that eliminates the
> netbios crap too. All that arping from browsers is going to go away.
> I also hear rumors that they are on the verge of breakthrough discoveries
> called NFS, and LPD too. Given enough time and money, they might
> eventually invent Unix."
> -- George Bonser in linux-kernel
Cheers,
RossW
=====
- [Freeciv-Dev] Re: Split patch (was Re: [RFC PATCH] init_techs), (continued)
- [Freeciv-Dev] Re: Split patch (was Re: [RFC PATCH] init_techs), Raimar Falke, 2001/09/26
- [Freeciv-Dev] Re: Split patch (was Re: [RFC PATCH] init_techs), Justin Moore, 2001/09/26
- [Freeciv-Dev] Re: Split patch (was Re: [RFC PATCH] init_techs), Ross W. Wetmore, 2001/09/26
- [Freeciv-Dev] Re: Split patch (was Re: [RFC PATCH] init_techs), Raimar Falke, 2001/09/27
- [Freeciv-Dev] Re: Split patch (was Re: [RFC PATCH] init_techs), Ross W. Wetmore, 2001/09/27
- [Freeciv-Dev] Re: Split patch (was Re: [RFC PATCH] init_techs), Reinier Post, 2001/09/28
- [Freeciv-Dev] Re: Split patch (was Re: [RFC PATCH] init_techs), Ross W. Wetmore, 2001/09/28
- [Freeciv-Dev] Re: Split patch (was Re: [RFC PATCH] init_techs), Reinier Post, 2001/09/30
- [Freeciv-Dev] Re: Split patch (was Re: [RFC PATCH] init_techs), Ross W. Wetmore, 2001/09/30
- [Freeciv-Dev] Re: Split patch (was Re: [RFC PATCH] init_techs), Raimar Falke, 2001/09/28
- [Freeciv-Dev] Re: Split patch (was Re: [RFC PATCH] init_techs),
Ross W. Wetmore <=
- [Freeciv-Dev] Re: Split patch (was Re: [RFC PATCH] init_techs), Raimar Falke, 2001/09/30
- [Freeciv-Dev] Re: Split patch (was Re: [RFC PATCH] init_techs), Ross W. Wetmore, 2001/09/30
- [Freeciv-Dev] Re: Split patch (was Re: [RFC PATCH] init_techs), Ross W. Wetmore, 2001/09/25
- [Freeciv-Dev] Re: [RFC PATCH] init_techs, Arien Malec, 2001/09/22
- [Freeciv-Dev] Re: [RFC PATCH] init_techs, Arien Malec, 2001/09/22
- [Freeciv-Dev] Re: [RFC PATCH] init_techs, Justin Moore, 2001/09/23
- [Freeciv-Dev] Re: [RFC PATCH] init_techs, Daniel L Speyer, 2001/09/23
- [Freeciv-Dev] Re: [RFC PATCH] init_techs, Arien Malec, 2001/09/23
- [Freeciv-Dev] Re: [RFC PATCH] init_techs, Justin Moore, 2001/09/24
- [Freeciv-Dev] Re: [RFC PATCH] init_techs, Arien Malec, 2001/09/23
|
|