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

Allocator #1

@jklmnn

Description

@jklmnn

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions