Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > sci.electronics.design > #483143
| From | David Brown <david.brown@hesbynett.no> |
|---|---|
| Newsgroups | sci.electronics.design |
| Subject | Re: Paper on dynamic memory allocation for real-time systems |
| Date | 2017-10-27 09:25 +0200 |
| Organization | A noiseless patient Spider |
| Message-ID | <osun1j$6pf$1@dont-email.me> (permalink) |
| References | <%D4GB.50140$6V2.21096@fx21.iad> <osihhn$r04$2@dont-email.me> <85uqucp76e1m9j14ito1m9kqr5fnukkg2o@4ax.com> <osp96g$4n2$1@gonzo.alcatraz> |
On 25/10/17 07:58, Jasen Betts wrote: > On 2017-10-23, upsidedown@downunder.com <upsidedown@downunder.com> wrote: >> On Sun, 22 Oct 2017 16:38:15 -0000 (UTC), Cursitor Doom >> <curd@notformail.com> wrote: >> >>> On Thu, 19 Oct 2017 12:44:43 -0400, bitrex wrote: >>> >>>> "Dynamic memory allocation has been used for decades. However, it has >>>> seldom been used in real-time systems since the worst case of spatial >>>> and temporal requirements for allocation and deallocation operations is >>>> either unbounded or bounded but with a very large bound." >>> >>> >>> Never really understood why C had such a notorious issue with DMA (the >>> free() function in particular) but I'm willing to be disabused of my >>> outstanding ignorance of the matter if anyone knows. >> >> I have often wondered, why C-programmers are so keen of using dynamic >> memory allocation instead of stack allocation. Is it because some >> early processors had a very limited stack, typically intended only for >> return addresses ? > > yeah, 8086 had only a 16 bit stack pointer but I never tried alloca in > a huge memory model. > > in the 8 bit world > > 6800 had only an 8 bit stack pointer, > and PIC16 even fewer, and stack > outside of main memory. > > AVR and Z80 have 16 bit stack pointers (Some AVRs have 16-bit stack pointers, but that's nit-picking.) > > >> In Pascal, you could allocate short lived memory areas on the stack >> and pass a pointer to that stack area as a procedure parameter. > > In C too, "alloca()" I think the "a" on the end stands for "auto" > > The standard does not require that it be allocated on the stack, but > if "longjmp()" is also provided, the only sensible implementation > (that I am aware of) is to do it that way. The C standard does not require a stack at all. A stack is, of course, the most efficient known mechanism for function calls, local variables, parameters, etc. - but it is not required by C. There are devices with no data stack and only a small dedicated hardware return stack (like small PIC's and some AVR Tiny devices), and plenty of devices with such inefficient access to data on the stack that compilers use static memory allocations for parameters and local variables (like many old-style 8-bit microcontrollers). The C standard also does not have alloca(). It is, however, in the Posix standards - and there a stack /is/ required. longjmp() is in the C standard, but is required only for "hosted" implementations and not for "freestanding" implementations. Devices like the AVR Tiny without a stack are unlikely to support longjmp(). (I haven't checked gcc's support here - as someone interested in clear, structured and reliable coding, I would not touch longjmp with a bargepole.) There are a few C implementations for bigger systems that do not have a normal stack as such. AFAIUI, there are are some mainframe systems where function frames are allocated in a linked list in a heap, rather than on a stack. And these should support longjmp. But whether it is an efficient implementation is another matter - the C standard only requires that it works according to spec, not that it is a "sensible" implementation! > >> Of course, this was simplified by having source level nested procedures, > > GCC has that in C too, not sure if it's part of some C standard or > purely a GCC extension. It is not part of any C standard - it is a gcc extension. gcc supports a number of languages, not just C and C++. Amongst others it supports Ada, which /does/ have nested procedures. (It also has out-of-tree support for Pascal.) Since the machinery is all in place in the compiler, and there was a clear and obvious syntax, gcc developers decided to make it available in C also. But the implementation of nested functions in C requires trampolines on many architectures - executable code snippets on the stack. This breaks code safety restrictions about non-executable stacks. If you want nested functions, you would be better to use C++ and lambdas rather than gcc's extension to C here. > > -- > This email has not been checked by half-arsed antivirus software > I wonder if your half-arsed antivirus software would have spotted the error in your signature delimiter - or that this is not an email? :-)
Back to sci.electronics.design | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Paper on dynamic memory allocation for real-time systems bitrex <bitrex@de.lete.earthlink.net> - 2017-10-19 12:44 -0400
Re: Paper on dynamic memory allocation for real-time systems Cursitor Doom <curd@notformail.com> - 2017-10-22 16:38 +0000
Re: Paper on dynamic memory allocation for real-time systems Bill Martin <wwm@wwmartin.net> - 2017-10-22 10:59 -0700
Re: Paper on dynamic memory allocation for real-time systems bitrex <bitrex@de.lete.earthlink.net> - 2017-10-22 14:01 -0400
Re: Paper on dynamic memory allocation for real-time systems Bill Martin <wwm@wwmartin.net> - 2017-10-22 11:09 -0700
Re: Paper on dynamic memory allocation for real-time systems pcdhobbs@gmail.com - 2017-10-22 11:16 -0700
Re: Paper on dynamic memory allocation for real-time systems bitrex <bitrex@de.lete.earthlink.net> - 2017-10-22 14:26 -0400
Re: Paper on dynamic memory allocation for real-time systems bitrex <bitrex@de.lete.earthlink.net> - 2017-10-22 14:30 -0400
Re: Paper on dynamic memory allocation for real-time systems bitrex <bitrex@de.lete.earthlink.net> - 2017-10-22 14:23 -0400
Re: Paper on dynamic memory allocation for real-time systems Cursitor Doom <curd@notformail.com> - 2017-10-22 22:49 +0000
Re: Paper on dynamic memory allocation for real-time systems pcdhobbs@gmail.com - 2017-10-22 16:15 -0700
Re: Paper on dynamic memory allocation for real-time systems upsidedown@downunder.com - 2017-10-23 08:17 +0300
Re: Paper on dynamic memory allocation for real-time systems Tom Gardner <spamjunk@blueyonder.co.uk> - 2017-10-23 09:21 +0100
Re: Paper on dynamic memory allocation for real-time systems David Brown <david.brown@hesbynett.no> - 2017-10-23 11:33 +0200
Re: Paper on dynamic memory allocation for real-time systems bitrex <bitrex@de.lete.earthlink.net> - 2017-10-23 12:00 -0400
Re: Paper on dynamic memory allocation for real-time systems David Brown <david.brown@hesbynett.no> - 2017-10-24 10:19 +0200
Re: Paper on dynamic memory allocation for real-time systems Tom Gardner <spamjunk@blueyonder.co.uk> - 2017-10-24 10:08 +0100
Re: Paper on dynamic memory allocation for real-time systems David Brown <david.brown@hesbynett.no> - 2017-10-24 11:31 +0200
Re: Paper on dynamic memory allocation for real-time systems bitrex <bitrex@de.lete.earthlink.net> - 2017-10-24 16:48 -0400
Re: Paper on dynamic memory allocation for real-time systems Tom Gardner <spamjunk@blueyonder.co.uk> - 2017-10-25 00:49 +0100
Re: Paper on dynamic memory allocation for real-time systems bitrex <bitrex@de.lete.earthlink.net> - 2017-10-24 20:04 -0400
Re: Paper on dynamic memory allocation for real-time systems Joseph Gwinn <joegwinn@comcast.net> - 2017-10-24 16:46 -0400
Re: Paper on dynamic memory allocation for real-time systems bitrex <bitrex@de.lete.earthlink.net> - 2017-10-23 10:53 -0400
Re: Paper on dynamic memory allocation for real-time systems David Brown <david.brown@hesbynett.no> - 2017-10-24 10:29 +0200
Re: Paper on dynamic memory allocation for real-time systems upsidedown@downunder.com - 2017-10-24 15:55 +0300
Re: Paper on dynamic memory allocation for real-time systems upsidedown@downunder.com - 2017-10-24 15:56 +0300
Re: Paper on dynamic memory allocation for real-time systems bitrex <bitrex@de.lete.earthlink.net> - 2017-10-23 12:35 -0400
Re: Paper on dynamic memory allocation for real-time systems Sylvia Else <sylvia@not.at.this.address> - 2017-10-24 19:26 +1100
Re: Paper on dynamic memory allocation for real-time systems Tom Gardner <spamjunk@blueyonder.co.uk> - 2017-10-24 10:12 +0100
Re: Paper on dynamic memory allocation for real-time systems Sylvia Else <sylvia@not.at.this.address> - 2017-10-25 11:55 +1100
Re: Paper on dynamic memory allocation for real-time systems Tom Gardner <spamjunk@blueyonder.co.uk> - 2017-10-25 08:40 +0100
Re: Paper on dynamic memory allocation for real-time systems Jasen Betts <jasen@xnet.co.nz> - 2017-10-25 05:58 +0000
Re: Paper on dynamic memory allocation for real-time systems Tom Gardner <spamjunk@blueyonder.co.uk> - 2017-10-25 08:42 +0100
Re: Paper on dynamic memory allocation for real-time systems kevin93 <kevin@whitedigs.com> - 2017-10-25 07:29 -0700
Re: Paper on dynamic memory allocation for real-time systems Jasen Betts <jasen@xnet.co.nz> - 2017-10-28 19:49 +0000
Re: Paper on dynamic memory allocation for real-time systems bitrex <bitrex@de.lete.earthlink.net> - 2017-10-25 17:28 -0400
Re: Paper on dynamic memory allocation for real-time systems David Brown <david.brown@hesbynett.no> - 2017-10-27 09:25 +0200
Re: Paper on dynamic memory allocation for real-time systems Sylvia Else <sylvia@not.at.this.address> - 2017-10-24 19:49 +1100
Re: Paper on dynamic memory allocation for real-time systems bitrex <bitrex@de.lete.earthlink.net> - 2017-10-24 19:20 -0400
csiph-web