Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.c > #402821
| Newsgroups | comp.lang.c, comp.lang.misc, comp.lang.lisp |
|---|---|
| From | Johann 'Myrkraverk' Oskarsson <johann@myrkraverk.invalid> |
| Subject | Real world switch () with the MPS memory pool system! |
| Organization | Watcom Pro Ltd. |
| Message-ID | <EUBxS.8919$mPXe.2290@fx06.ams4> (permalink) |
| Date | 2026-10-08 08:58 +0800 |
Cross-posted to 3 groups.
Dear comp.lang.c, comp.lang.misc, comp.lang.lisp,
Because this is a general programming example, using the MPS memory
pool system, and therefore used to /implement/ many programming lan-
guages, including Lisp, I've decided to cross post a little bit.
And because the switch () statement was a topic of discussion in comp.
lang.c only a short while ago, I present my real world example.
static mps_res_t Type_isfwd_fn( mps_addr_t addr )
{
Type_type type = addr ;
switch ( type->kind ) {
case Type_forwardType: return type->fwd ;
default: return NULL ;
}
}
Here, /Type/ is a generic type of something, with a specific variable
named /type/. It's not what I use in production, but will demonstrate
well enough without bothering /foo/ and /bar/.
The code is meant to check if this particular object has been forwarded
to a different generation of the garbage collector. And I believe it
does so adequately, though I have not explicitly tested it. All I can
say is that my previous runs of similar code have worked, and my appli-
cation didn't crash.
So the question here is, do you think this is reasonable C code, and
would you write something similar yourself? After all, /kind/ is an
enum, and the compiler might complain if you don't handle all the cases,
and not do that if you merely use an if (). I wouldn't know, as I don't
keep track of changes within G.C.C. nor clang anymore.
Another question is, would you consider using the MPS memory pool system
if you were to implement something garbage collected, like Common Lisp
or ML [1]?
And for the people disturbed by garbage collectors, does the above code
make you feel weird? Do you need psychological therapy after reading my
code?
Best wishes, and happy garbage collection!
[1] Unrelated to /machine learning/, of course.
--
Johann | email: invalid -> com | http://www.myrkraverk.com/blog/
I'm not from the Internet, I just work there. | via Easynews.com
https://bsky.app/profile/myrkraverk.bsky.social | for ( ;; ) _:;
Federated at https://fed.brid.gy/bsky/myrkraverk.bsky.social
Back to comp.lang.c | Previous | Next — Next in thread | Find similar | Unroll thread
Real world switch () with the MPS memory pool system! Johann 'Myrkraverk' Oskarsson <johann@myrkraverk.invalid> - 2026-10-08 08:58 +0800
Re: Real world switch () with the MPS memory pool system! Kaz Kylheku <046-301-5902@kylheku.com> - 2026-10-08 01:31 +0000
Re: Real world switch () with the MPS memory pool system! Johann 'Myrkraverk' Oskarsson <johann@myrkraverk.invalid> - 2026-10-10 04:26 +0800
Re: Real world switch () with the MPS memory pool system! Kaz Kylheku <046-301-5902@kylheku.com> - 2026-10-09 20:45 +0000
Re: Real world switch () with the MPS memory pool system! Johann 'Myrkraverk' Oskarsson <johann@myrkraverk.invalid> - 2026-10-10 05:02 +0800
Re: Real world switch () with the MPS memory pool system! Johann 'Myrkraverk' Oskarsson <johann@myrkraverk.invalid> - 2026-10-11 09:28 +0800
Re: Real world switch () with the MPS memory pool system! tfb <tfb@work.it.out> - 2026-10-10 09:45 +0000
Re: Real world switch () with the MPS memory pool system! George Neuner <gneuner2@comcast.net> - 2026-10-11 01:13 -0400
Re: Real world switch () with the MPS memory pool system! Johann 'Myrkraverk' Oskarsson <johann@myrkraverk.invalid> - 2026-10-11 14:45 +0800
Re: Real world switch () with the MPS memory pool system! tfb <tfb@work.it.out> - 2026-10-11 07:28 +0000
Re: Real world switch () with the MPS memory pool system! Johann 'Myrkraverk' Oskarsson <johann@myrkraverk.invalid> - 2026-10-11 15:41 +0800
Re: Real world switch () with the MPS memory pool system! George Neuner <gneuner2@comcast.net> - 2026-10-11 05:29 -0400
Re: Real world switch () with the MPS memory pool system! Tim Rentsch <tr.17687@z991.linuxsc.com> - 2026-10-08 06:03 -0700
Re: Real world switch () with the MPS memory pool system! ram@zedat.fu-berlin.de (Stefan Ram) - 2026-10-09 14:30 +0000
Re: Real world switch () with the MPS memory pool system! Johann 'Myrkraverk' Oskarsson <johann@myrkraverk.invalid> - 2026-10-10 04:41 +0800
csiph-web