Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.c > #74703

Re: Memory and error management approaches

From Ian Collins <ian-news@hotmail.com>
Newsgroups comp.lang.c
Subject Re: Memory and error management approaches
Date 2015-11-03 10:29 +1300
Message-ID <d9q2t5F7v31U4@mid.individual.net> (permalink)
References (2 earlier) <n17app$82n$1@speranza.aioe.org> <d9opetF6ovuU6@mid.individual.net> <n17cgd$cf2$1@speranza.aioe.org> <d9q0hqF7v31U2@mid.individual.net> <cad90f0b-d6a2-4069-8c88-8283ea338ae5@googlegroups.com>

Show all headers | View raw


supercat@casperkitty.com wrote:
> On Monday, November 2, 2015 at 2:49:08 PM UTC-6, Ian Collins wrote:
>> There are good reasons why no attempt at bolting on an exception
>> mechanism on to C has ever caught on.
>
> It's all very nice and convenient to assume that things will always behave
> as expected, at least until the unexpected happens.  Once one opens up that
> can of worms, there often is no really good approach--the best one can do
> is try to manage the least-evil approach.  The scenario where I see a
> longjmp-based recovery as being appropriate would be one where inner-level
> code wouldn't be likely to be acquiring and releasing many resources that
> outer-level code didn't know about, so it wouldn't be necessary to use
> mid-level setjmp for most scenarios.

True enough but once added, longjmp based recovery makes the code 
vulnerable to any changes between the jump and landing site which do 
allocate a resource.  In short it makes the code fragile.

>> The time to look at custom allocation is after extensive testing and
>> profiling shows a bottleneck with dynamic memory.
>
> I've used custom allocators often in embedded systems where requirements
> could be met in such a way that fragmentation would never occur.  On hosted
> systems, non-library code should generally use malloc/free, but that doesn't
> mean library code shouldn't allow clients to use some other forms of
> allocation that may be more appropriate to their needs.

You wouldn't really want a library to use a different allocation scheme 
to the rest of the application, especially if the scheme allocates its 
own working memory.

In cases such as parsers, the library writer has no way of knowing which 
allocation scheme is appropriate for a particular use case.  Consider 
the differing requirements of two use cases I mentioned earlier: small 
SOAP packets and large office documents.

-- 
Ian Collins

Back to comp.lang.c | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

Memory and error management approaches "Morten W. Petersen" <morphex@gmail.com> - 2015-11-02 10:17 +0100
  Re: Memory and error management approaches Ian Collins <ian-news@hotmail.com> - 2015-11-02 22:25 +1300
    Re: Memory and error management approaches "Morten W. Petersen" <morphex@gmail.com> - 2015-11-02 10:36 +0100
      Re: Memory and error management approaches Ian Collins <ian-news@hotmail.com> - 2015-11-02 22:41 +1300
        Re: Memory and error management approaches "Morten W. Petersen" <morphex@gmail.com> - 2015-11-02 11:05 +0100
          Re: Memory and error management approaches Jorgen Grahn <grahn+nntp@snipabacken.se> - 2015-11-02 12:15 +0000
            Re: Memory and error management approaches "Morten W. Petersen" <morphex@gmail.com> - 2015-11-02 20:31 +0100
          Re: Memory and error management approaches Ian Collins <ian-news@hotmail.com> - 2015-11-03 09:48 +1300
            Re: Memory and error management approaches supercat@casperkitty.com - 2015-11-02 13:17 -0800
              Re: Memory and error management approaches Ian Collins <ian-news@hotmail.com> - 2015-11-03 10:29 +1300
                Re: Memory and error management approaches supercat@casperkitty.com - 2015-11-02 13:48 -0800
            Re: Memory and error management approaches "Morten W. Petersen" <morphex@gmail.com> - 2015-11-02 22:31 +0100
              Re: Memory and error management approaches Ian Collins <ian-news@hotmail.com> - 2015-11-03 11:02 +1300
                Re: Memory and error management approaches supercat@casperkitty.com - 2015-11-02 15:21 -0800
              Re: Memory and error management approaches <william@wilbur.25thandClement.com> - 2015-11-03 17:24 -0800
                Re: Memory and error management approaches Ian Collins <ian-news@hotmail.com> - 2015-11-04 14:38 +1300
                Re: Memory and error management approaches <william@wilbur.25thandClement.com> - 2015-11-04 10:48 -0800
                Re: Memory and error management approaches supercat@casperkitty.com - 2015-11-04 11:28 -0800
                Re: Memory and error management approaches James Kuyper <jameskuyper@verizon.net> - 2015-11-04 14:54 -0500
                Re: Memory and error management approaches Gareth Owen <gwowen@gmail.com> - 2015-11-06 07:50 +0000
                Re: Memory and error management approaches <william@wilbur.25thandClement.com> - 2015-11-06 11:40 -0800
                Re: Memory and error management approaches Ian Collins <ian-news@hotmail.com> - 2015-11-07 09:38 +1300
                Re: Memory and error management approaches Jorgen Grahn <grahn+nntp@snipabacken.se> - 2015-11-06 20:55 +0000
                Re: Memory and error management approaches Malcolm McLean <malcolm.mclean5@btinternet.com> - 2015-11-07 02:23 -0800
                Re: Memory and error management approaches Jorgen Grahn <grahn+nntp@snipabacken.se> - 2015-11-07 11:29 +0000
                Re: Memory and error management approaches Malcolm McLean <malcolm.mclean5@btinternet.com> - 2015-11-07 04:18 -0800
                Re: Memory and error management approaches asetofsymbols@gmail.com - 2015-11-07 05:41 -0800
                Re: Memory and error management approaches asetofsymbols@gmail.com - 2015-11-07 06:27 -0800
                Re: Memory and error management approaches Sjouke Burry <burrynulnulfour@ppllaanneett.nnll> - 2015-11-07 18:20 +0100
                Re: Memory and error management approaches Malcolm McLean <malcolm.mclean5@btinternet.com> - 2015-11-07 10:28 -0800
                Re: Memory and error management approaches gazelle@shell.xmission.com (Kenny McCormack) - 2015-11-07 19:01 +0000
                Re: Memory and error management approaches raltbos@xs4all.nl (Richard Bos) - 2015-11-10 16:14 +0000
                Re: Memory and error management approaches Gareth Owen <gwowen@gmail.com> - 2015-11-10 21:13 +0000
                Re: Memory and error management approaches Jorgen Grahn <grahn+nntp@snipabacken.se> - 2015-11-10 19:26 +0000
                Re: Memory and error management approaches Malcolm McLean <malcolm.mclean5@btinternet.com> - 2015-11-03 18:25 -0800
                Re: Memory and error management approaches "Morten W. Petersen" <morphex@gmail.com> - 2015-11-06 10:05 +0100
    Re: Memory and error management approaches Malcolm McLean <malcolm.mclean5@btinternet.com> - 2015-11-02 02:15 -0800
      Re: Memory and error management approaches Jorgen Grahn <grahn+nntp@snipabacken.se> - 2015-11-02 12:01 +0000
        Re: Memory and error management approaches Malcolm McLean <malcolm.mclean5@btinternet.com> - 2015-11-02 06:05 -0800
          Re: Memory and error management approaches Jorgen Grahn <grahn+nntp@snipabacken.se> - 2015-11-02 17:18 +0000
            Re: Memory and error management approaches Malcolm McLean <malcolm.mclean5@btinternet.com> - 2015-11-02 09:27 -0800
              Re: Memory and error management approaches Jorgen Grahn <grahn+nntp@snipabacken.se> - 2015-11-02 23:02 +0000
              Re: Memory and error management approaches Ian Collins <ian-news@hotmail.com> - 2015-11-03 12:07 +1300
                Re: Memory and error management approaches Malcolm McLean <malcolm.mclean5@btinternet.com> - 2015-11-02 15:23 -0800
            Re: Memory and error management approaches supercat@casperkitty.com - 2015-11-02 10:28 -0800
      Re: Memory and error management approaches Ian Collins <ian-news@hotmail.com> - 2015-11-03 09:34 +1300
        Re: Memory and error management approaches Malcolm McLean <malcolm.mclean5@btinternet.com> - 2015-11-02 14:05 -0800
          Re: Memory and error management approaches Ian Collins <ian-news@hotmail.com> - 2015-11-03 11:27 +1300
            Re: Memory and error management approaches Malcolm McLean <malcolm.mclean5@btinternet.com> - 2015-11-03 18:15 -0800

csiph-web