Skip to content
This repository has been archived by the owner on Aug 12, 2024. It is now read-only.

Allocator #1

Open
jklmnn opened this issue Nov 19, 2019 · 0 comments
Open

Allocator #1

jklmnn opened this issue Nov 19, 2019 · 0 comments

Comments

@jklmnn
Copy link
Member

jklmnn commented Nov 19, 2019

The allocator interface is used to allocate chunks from an array. It is an empty generic package that can be instantiated with different predefined allocators. Any interface requiring an allocator will take an instance of the allocator package:

--  Allocator interface
generic
   type Context is private;
   type Element_Range is range <>;
   with Procedure Initialize (Ctx  : out Context:
                              Size :     Element_Range);
   with Procedure Allocate (Ctx    :     Context;
                            Length :     Element_Range;
                            Start  : out Element_Range);
   with Procedure Free (Ctx   : Context;
                        Start : Element_Range);
package Allocator_Generic is
end Allocator_Generic;

--  Allocator implementation
package Simple_Allocator is

   type Element_Range is Integer range 0 .. Integer'Last;
   type Context is record
      Size : Element_Range;
      ...
   end record;

   procedure Initialize (Ctx  : out Context
                         Size :     Element_Range);

   procedure Allocate (R :     Element_Range;
                       S : out Element_Range;
                       L : out Element_Range);

   procedure Free (R : Element_Range;
                   S : Element_Range);

   package Allocator is new Allocator_Generic (Element_Range, Initialize, Allocate, Free);

end Simple_Allocator;

--  Package using an arbitrary allocator
generic
   with package Allocator_Generic (<>);
package Block_Allocator is
end Block_Allocator;

The allocator does not work on the payload data but only on a specified range and size. It can allocate from a list of arbitrary elements.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant