Skip to content

micropython-specific call to pre-allocate object to a given size #917

Closed

Description

@pfalcon

Here's the idea I had for a long time, remember at right time to record it: to fight memory fragmentation, etc. it would be nice to have call like:

obj = micropython.alloc(type, 10)

which would create a container object which could hold up to 10 items without reallocations. Obvious candidates for type are list and dict, and support for more types can be added as makes sense.

Note that we still can stay compatible with other Pythons by providing shim:

def alloc(type, sz):
    return type()

Activity

  1. dpgeorge commented on Oct 18, 2014

    @dpgeorge
    Member

    This is a neat idea. It would be pretty easy to implement, since dict and list already have C functions to preallocate. bytearray is not needed since its constructor already does this.

  2. added a commit that references this issue on Jun 12, 2018
  3. dpgeorge commented on Jun 24, 2022

    @dpgeorge
    Member

    Closing due to inactivity.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementFeature requests, new feature implementations

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions