[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: sorting in C
From: |
Eli Zaretskii |
Subject: |
Re: sorting in C |
Date: |
Sun, 27 Feb 2022 11:29:29 +0200 |
> From: Andrew Cohen <acohen@ust.hk>
> Date: Sun, 27 Feb 2022 17:11:53 +0800
>
> EZ> However, from your description, it doesn't sound like the more
> EZ> optimal approach of allocating dynamically is much more
> EZ> complicated. In particular, what Mattias said should be easy
> EZ> using the unwind-protect machinery we already have (and use in
> EZ> many similar situations). See the calls to
> EZ> record_unwind_protect_ptr whose first argument is 'xfree'. We
> EZ> also have reallocation routines ready to be used.
>
> That is how I am handling it now, but I'm not sure if I have it right
> (sorry for the naive question):
>
> When I need new memory I call
>
> : specpdl_ref sa_count = SPECPDL_INDEX ();
> : a = (Lisp_Object *) record_xmalloc (need * sizeof (Lisp_Object));
>
> and I save =sa_count=; I guess =record_xmalloc= handles freeing the
> memory on exception. Later during the sorting process I free the memory
> explicitly with
>
> : safe_free (sa_count)
>
> Does this seem right? (Probably, since I've been running this way for
> awhile and would have expected lots of problems if I weren't allocating
> and freeing the memory :))
I'd rather you didn't use safe_free, since that is for SAFE_ALLOCA
etc. Just use unbind_to directly, like we do elsewhere where
record_xmalloc is used.
- Re: sorting in C, (continued)
- Re: sorting in C, Eli Zaretskii, 2022/02/23
- Re: sorting in C, Andrew Cohen, 2022/02/23
- Re: sorting in C, Eli Zaretskii, 2022/02/23
- Re: sorting in C, Andrew Cohen, 2022/02/23
- Re: sorting in C, Andrew Cohen, 2022/02/23
- Re: sorting in C, Eli Zaretskii, 2022/02/23
- Re: sorting in C, Andrew Cohen, 2022/02/26
- Re: sorting in C, Andrew Cohen, 2022/02/26
- Re: sorting in C, Eli Zaretskii, 2022/02/27
- Re: sorting in C, Andrew Cohen, 2022/02/27
- Re: sorting in C,
Eli Zaretskii <=
- Re: sorting in C, Andrew Cohen, 2022/02/27
- Re: sorting in C, Yuri Khan, 2022/02/23
- Re: sorting in C, Andrew Cohen, 2022/02/23
Re: sorting in C, Lars Ingebrigtsen, 2022/02/22