comp.lang.ada
 help / color / mirror / Atom feed
* Generic Embedded List Nodes
@ 2016-06-18 22:52 Warren
  2016-06-18 23:40 ` Jeffrey R. Carter
                   ` (4 more replies)
  0 siblings, 5 replies; 52+ messages in thread
From: Warren @ 2016-06-18 22:52 UTC (permalink / raw)


Getting back to Ada after a hiatus, I currently have a need to build a 
generic package to implement "embedded list node" lists. The advantage 
is high performance in a server setting to avoid underlying malloc/free
calls.

The idea is that the list node resides within the structure/tagged type,
and acts as a doubly linked list node when in a list. The Emb_Node can
be used as a list head when itself (or as part of another structure). This
kind of thing is done in the Linux kernel, for example.
   
The Emb_Node and its operations are trivial. The problem occurs when
you traverse a linked list of Emb_Nodes (or its derived type). With
a given node, I need to then access the object that _contains_ it. In
C/C++ you do some offset calculation from the node address back to
the owning struct/class.

My idea (in Ada) was to save some kind of access value in a type
derived from Emb_List. But that is where the trouble starts.

package Emb_List is
         
   type Emb_Node is tagged private;
             
   procedure Insert_Head(Head: access Emb_Node; Node: access Emb_Node);
   procedure Unlink(Node: access Emb_Node);

private

   type Emb_Node is tagged
      record
         Next:    access Emb_Node;  -- Ptr to next node in list (if any)
         Prev:    access Emb_Node;  -- Ptr to prev node in list (if any)
      end record;
   
end Emb_List;
   
The generic extension (below) was intended to hold the reference to the
containing object, which is where the trouble starts. I was hoping this
would work, but running into "missing full declaration for private
extension".

generic
   type Object_Type is tagged private;
package Emb_List.Nodes is

   type Node_Type(Obj: access Object_Type) is new Emb_Node;
   
   function Object(Node: Node_Type) return Object_Type;
   
end Emb_List.Nodes;


The other end of the challenge will be to have the Node_Type save the
owning object access value at the time it is created:

   type Something_New_Type is tagged
      record
         Stuff:                  Natural;
         Timeout_Node:  Node_Type(some access to this record);
         ...
      end record;
      
I am trying to avoid using 'Address for this, since there is likely a
way to do this "right".

Warren.

^ permalink raw reply	[flat|nested] 52+ messages in thread

end of thread, other threads:[~2016-07-02  1:55 UTC | newest]

Thread overview: 52+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-06-18 22:52 Generic Embedded List Nodes Warren
2016-06-18 23:40 ` Jeffrey R. Carter
2016-06-19  2:15   ` Warren
2016-06-19  3:04     ` Jeffrey R. Carter
2016-06-19  2:14 ` Jeremiah
2016-06-19  2:21   ` Warren
2016-06-19  2:50     ` Warren
2016-06-19  4:45       ` Simon Wright
2016-06-19 18:27         ` Warren
2016-06-19 19:04           ` Dmitry A. Kazakov
2016-06-19 20:13             ` Warren
2016-06-19 20:35               ` Dmitry A. Kazakov
2016-06-20  2:42                 ` Warren
2016-06-20  7:25                   ` Dmitry A. Kazakov
2016-06-20 12:26                     ` Warren
2016-06-20 19:33                       ` Niklas Holsti
2016-06-21  2:20                         ` Warren
2016-06-21  5:52                           ` Niklas Holsti
2016-06-21  7:15                             ` Dmitry A. Kazakov
2016-06-21 18:54                               ` Niklas Holsti
2016-06-21 19:54                                 ` Dmitry A. Kazakov
2016-06-21 10:31                             ` Warren
2016-06-21 17:13                               ` Jeffrey R. Carter
2016-06-21 18:56                                 ` Niklas Holsti
2016-06-21 20:13                                   ` Warren
2016-06-21 21:38                               ` Niklas Holsti
2016-06-23  2:12                                 ` Warren
2016-06-23  8:19                                   ` Niklas Holsti
2016-06-23 12:37                                     ` Warren
2016-06-23 15:36                                       ` Niklas Holsti
2016-06-24  1:55                                         ` Warren
2016-06-24 12:49                                         ` Warren
2016-06-25  5:50                                           ` Niklas Holsti
2016-06-26  1:36                                             ` Warren
2016-07-01 13:49                                             ` Warren
2016-07-01 16:28                                               ` Warren
2016-06-24 20:25                                         ` Warren
2016-06-22 13:01                               ` G.B.
2016-06-23  2:30                                 ` Warren
2016-06-20  6:08 ` Niklas Holsti
2016-06-20 12:20   ` Warren
2016-06-20 19:47 ` Shark8
2016-06-21  2:28   ` Warren
2016-06-21  7:21     ` Dmitry A. Kazakov
2016-06-21 10:32       ` Warren
2016-06-21 11:56         ` Dmitry A. Kazakov
2016-06-21 13:39           ` Warren
2016-06-21 14:04             ` Dmitry A. Kazakov
2016-06-23  0:37     ` Randy Brukardt
2016-06-23  2:25       ` Warren
2016-07-01 19:50 ` brbarkstrom
2016-07-02  1:55   ` Warren

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox