Table of contents
1.
Introduction
2.
pyglet.graphics.allocation
2.1.
1. exceptionAllocatorMemoryException(requested_capacity)
2.2.
2. classAllocator(capacity)
2.2.1.
alloc(size)
2.2.2.
dealloc(start, size)
2.2.3.
get_allocated_regions()
2.2.4.
get_fragmentation()
2.2.5.
get_fragmented_free_size()
2.2.6.
get_free_size()
2.2.7.
get_usage()
2.2.8.
realloc(start, size, new_size)
2.2.9.
set_capacity(size)
3.
Frequently Asked Questions
3.1.
What is a pyglet?
3.2.
What is pyglet.graphics.allocation module?
3.3.
What is classAllocator?
4.
Conclusion
Last Updated: Mar 27, 2024

pyglet.graphics.allocation

Author Nagendra
0 upvote
Career growth poll
Do you think IIT Guwahati certified course can help you in your career?

Introduction

Pyglet is a simple yet powerful library for creating aesthetically rich GUI programs on Windows, Mac OS, and Linux, such as games and multimedia. This Python-only package includes capabilities such as windowing, user interface event management, joysticks, OpenGL graphics, loading photos and movies, and playing sounds and music. Pyglet is released under the BSD open-source licence, which allows it to be used in both commercial and open-source projects with few restrictions. The article explains the details of the pyglet.graphics.allocation module, different classes of pyglet.graphics.allocation, along with its predefined functions.

pyglet.graphics.allocation

It defines an algorithm for allocating memory for vertex arrays and buffers. The area allocator is used to distribute vertex indices over many buffers in a vertex domain. (Any abstract buffer supplied by pyglet.graphics.vertexbuffer is referred to as a "buffer"). The allocator will occasionally ask the buffers for more space. When there isn't enough room to fulfil an allocation, the current policy is to double the buffer size. The buffer is never shrunk in size. The allocator merely keeps track of free space; the caller is responsible for keeping track of the allocated regions.

1. exceptionAllocatorMemoryException(requested_capacity)

The buffer is insufficient to complete an allocation.
When an operation fails owing to a lack of buffer space, Allocator methods raise this exception. After increasing the buffer to at least the requested capacity, the procedure should be retried (guaranteed to pass a second time).

2. classAllocator(capacity)

It is the implementation of buffer space allocation.

alloc(size)

In the buffer, it is used to allocate memory. If the allocation cannot be completed, an AllocatorMemoryException is thrown.

Parameters:

  • size (int) – It represents the size of the region to allocate.

Return type: int
Returns: It returns the starting index of the allocated region.

dealloc(start, size)

It is used to deallocate a region of the buffer.

Parameters:

  • start (int) – This is the starting index of the region.
  • size (int) – This represents the size of the region.

get_allocated_regions()

It is used to retrieve a list of (aggregate) allocated regions. This method yields (starts, sizes), where starts is a list of the area starting indices and sizes are their corresponding lengths.
Return type: (list, list)

get_fragmentation()

Return the percentage of vacant space that cannot be expanded.
Return type: float

get_fragmented_free_size()

It returns the amount of space unused, excluding the final free block.
Return type: int

get_free_size()

Return the unused space amount.
Return type: int

get_usage()

Return a percentage of the current allocated capacity.
Return type: float

realloc(start, size, new_size)

It is used to reallocate some buffer space. The region may often be resized in-place. This is more efficient than making separate dealloc and alloc calls. If the allocation cannot be completed, an AllocatorMemoryException is thrown.

Parameters:

  • start (int) – This is the current starting index of the region.
  • size (int) – This represents the Current size of the region.
  • new_size (int) – It is the new size of the region.

set_capacity(size)

It is used to resize the buffer size limit. It is impossible to limit the capacity.

Parameters:

  • size (int) – The new buffer's maximum size.

 

Frequently Asked Questions

What is a pyglet?

Pyglet is a Python library that provides an object-oriented application programming interface for the development of games and other multimedia applications.

What is pyglet.graphics.allocation module?

The pyget.graphics.allocation module defines an algorithm for allocating memory for vertex arrays and buffers.

What is classAllocator?

The classAllocacator is the implementation of buffer space allocation.

Conclusion

In this article, we have extensively discussed pyglet.graphics.allocation. The article explains the details of pyglet.graphics.allocation and details of its different classes and predefined functions.
We hope that this blog has helped you enhance your knowledge regarding pyglet.graphics.allocation, and if you would like to learn more, check out our articles on pyglet. You can refer to our guided paths on the Coding Ninjas Studio platform to learn more about DSADBMSCompetitive ProgrammingPythonJavaJavaScript, etc. To practice and improve yourself in the interview, you can also check out Top 100 SQL problemsInterview experienceCoding interview questions, and the Ultimate guide path for interviews.

Do upvote our blog to help other ninjas grow. 

Happy Coding!!

Live masterclass