Proposal: Adding SplFixedArray->push() and SplFixedArray->pop()
| From: | tyson andre | Date: | Tue, 29 Dec 2020 17:03:55 +0000 |
| Subject: | Proposal: Adding SplFixedArray->push() and SplFixedArray->pop() | ||
| Groups: | php.internals | ||
| Request: | Send a blank email to internals+get-112639@lists.php.net to get a copy of this message | ||
Hi Internals,
Currently, PHP doesn't have a built in memory-efficient array type with convenient push, pop,
and other operations, similar to a list/vector in other languages.
The closest built in in SPL is
[SplFixedArray](https://www.php.net/manual/en/class.splfixedarray.php)
https://www.php.net/manual/en/class.splstack.php
uses a doubly linked list, which uses much more memory and time than sequential memory.
Contrary to the name and description in https://www.php.net/manual/en/class..splfixedarray.php,
the class is already resizable.
The resize method is setSize - https://www.php.net/manual/en/splfixedarray.setsize.php
(increasing size is efficient - erealloc will extend the underlying array into free memory if there
is nothing in the way)
Many programming languages have a memory-efficient list/vector type that can be conveniently
appended to and popped from.
https://docs.python.org/3/tutorial/datastructures.html#more-on-lists
https://www.cplusplus.com/reference/vector/vector/
https://docs.ruby-lang.org/en/2.0.0/Array.html#method-i-push
Is there any interest in adding this? It would be much more efficient to add these in C.
Thanks,
- Tyson