Re: A modern way to solve the "callback problem" from a subroutine?



GaryScott wrote:
(snip)

I'm not really as anti-pointer as that sounded, however, it is
possible to solve these problems in other ways. You can write a
linked list (double, single, skip) functionality without pointers and
in my opinion more clearly. "Best" is highly subjective. Clear,
clean, easy to understand code may be best for some, whereas,
efficient memory utilization might be someone else's criterion.

Efficient memory utilization is often important. When Fortran
was young, computers only had one program in storage at a time so
that there was no reason not to give that program all available storage.
Many Fortran "tricks" are based on how to use that memory within
the program.

When you have more than one program running and using memory at
the same time, efficient use of memory is important. When a
program can't anticipate its memory usage, dynamic allocation
is needed. In the case of a linked list of unknown and highly
variable length, pointers allow more efficient memory usage.
If the total length is known, or approximately known, then
an array of appropriate size can be allocated and array
elements referenced as part of a list. (I have done
that even in C.)

I've
solved virtually every type of problem without ever needing pointers.
The only exceptions have been the need to associate an application
memory buffer or structure with allocated memory returned by the
operating system, or to assign a callback procedure. I would add that
if linked lists are so overwhelmingly beneficial, then we should build
them into the language, perhaps as an intrinsic object.

PL/I has locate mode I/O for that case. One can read data in such
that the system supplies a pointer to the data in the input buffer
or write data directly into the output buffer. That saves copying
large amounts of data unnecessarily, especially for read-modify-write
when only small modifications are being made.

-- glen

.



Relevant Pages

  • Re: Singly Linked List in C
    ... <stuff about the xored pointer trick to get pseudo-doubly linked lists ... You can achieve a greater increase in memory ... XOR technique can be applied - in ANSI C - without relying on ... Pointers generally have a range much larger than is necessary to index ...
    (comp.programming)
  • Re: Is this string input function safe?
    ... return a pointer to mallocated memory holding one input string, ... complains about use of deallocated pointers, ... mallocating an appropriate amount of memory. ... the contents of the buffer are indeterminate (for different ...
    (comp.lang.c)
  • Re: How to allocate memory for a linked list of pointers in a kernel process
    ... are you sure you access memory at proper ... lists using pointers of course. ... When the kernel routines need to allocate a ... Are you aware that the kernel contains routines to do doubly linked lists ...
    (microsoft.public.win32.programmer.kernel)
  • Re: Memory marshaling in WinCE6
    ... It is asyncronous when you have another thread that reads/writes the buffer. ... Bruce.Eitman AT EuroTech DOT com ... In fact, I don't have any embedded pointers, it is a pointer to the ... buffer I want to fill with the data stored in internal memory. ...
    (microsoft.public.windowsce.platbuilder)
  • Re: Problem with offset based linked list
    ... offset's instead on pointers to store the linked list in the shared ... Shared memory is not guaranteed to be at the same address in all process ... That's the reason why one needs to use offsets in place of pointers ... when having linked lists in the shared memory? ...
    (comp.lang.c)