Skip to content

Commit

Permalink
Stated the memory and compute overhead
Browse files Browse the repository at this point in the history
Signed-off-by: Andreas Maier <andreas.r.maier@gmx.de>
  • Loading branch information
andy-maier committed Apr 12, 2021
1 parent 93a954a commit a1aae31
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 8 deletions.
17 changes: 13 additions & 4 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,19 @@ collection object will be visible in the view object.
Creating an immutable view on a collection does not copy the collection and
is therefore much faster than creating an immutable copy of the collection.

This is useful if a method or function maintains data in form of a mutable
collection and is intended to return that data but users should not be able to
modify the data. The underlying collection can be updated by the method or
function as needed, but the caller only gets an immutable view on it.
The memory overhead of using immutable views is very small: An object
of any of the view classes in the **immutable-views** package occupies 48 Bytes
(measured in CPython 3.8 on macOS), and because the view object only has a
reference to its underlying collection object, that size is independent of the
number of items in the collection.

The compute overhead is also very small, it is basically an additional function
call to the corresponding function of the underlying collection.

Immutable views are useful if a method or function maintains data in form of a
mutable collection and is intended to return that data but users should not be
able to modify the data. The underlying collection can be updated by the method
or function as needed, but the caller only gets an immutable view on it.

The view classes in the **immutable-views** package implement the complete
behavior of the corresponding Python collection types except for any
Expand Down
2 changes: 2 additions & 0 deletions docs/changes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ Released: not yet

* Removed dependency to 'six' package.

* Stated the memory and compute overhead of using immutable view classes.

**Cleanup:**

* Docs: Simplified the introduction section.
Expand Down
17 changes: 13 additions & 4 deletions docs/usage.rst
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,19 @@ collection object will be visible in the view object.
Creating an immutable view on a collection does not copy the collection and
is therefore much faster than creating an immutable copy of the collection.

This is useful if a method or function maintains data in form of a mutable
collection and is intended to return that data but users should not be able to
modify the data. The underlying collection can be updated by the method or
function as needed, but the caller only gets an immutable view on it.
The memory overhead of using immutable views is very small: An object
of any of the view classes in the **immutable-views** package occupies 48 Bytes
(measured in CPython 3.8 on macOS), and because the view object only has a
reference to its underlying collection object, that size is independent of the
number of items in the collection.

The compute overhead is also very small, it is basically an additional function
call to the corresponding function of the underlying collection.

Immutable views are useful if a method or function maintains data in form of a
mutable collection and is intended to return that data but users should not be
able to modify the data. The underlying collection can be updated by the method
or function as needed, but the caller only gets an immutable view on it.

The view classes in the **immutable-views** package implement the complete
behavior of the corresponding Python collection types except for any
Expand Down

0 comments on commit a1aae31

Please sign in to comment.