Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cpython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cpython
Commits
497bdd69
Commit
497bdd69
authored
Jun 10, 2002
by
Michael W. Hudson
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Tweak the description of pymalloc. Mention pymemcompat.h.
parent
b3bfa7f9
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
34 additions
and
24 deletions
+34
-24
Doc/whatsnew/whatsnew23.tex
Doc/whatsnew/whatsnew23.tex
+34
-24
No files found.
Doc/whatsnew/whatsnew23.tex
View file @
497bdd69
...
...
@@ -357,9 +357,10 @@ or warnings.filterwarnings().
An experimental feature added to Python 2.1 was a specialized object
allocator called pymalloc, written by Vladimir Marangozov. Pymalloc
was intended to be faster than the system
\function
{
malloc()
}
and have
less memory overhead. The allocator uses C's
\function
{
malloc()
}
function to get large pools of memory, and then fulfills smaller
memory requests from these pools.
less memory overhead for typical allocation patterns of Python
programs. The allocator uses C's
\function
{
malloc()
}
function to get
large pools of memory, and then fulfills smaller memory requests from
these pools.
In 2.1 and 2.2, pymalloc was an experimental feature and wasn't
enabled by default; you had to explicitly turn it on by providing the
...
...
@@ -378,32 +379,34 @@ and \function{free()}, meaning that if you accidentally called
mismatched functions, the error wouldn't be noticeable. When the
object allocator is enabled, these functions aren't aliases of
\function
{
malloc()
}
and
\function
{
free()
}
any more, and calling the
wrong function to free memory
will
get you a core dump. For example,
if memory was allocated using
\function
{
Py
Mem
_
New()
}
, it has to be
freed using
\function
{
PyMem
_
Del()
}
, not
\function
{
free()
}
. A few
modules included with Python fell afoul of this and had to be fixed;
doubtless there are more third-party modules that will have the sam
e
problem.
wrong function to free memory
may
get you a core dump. For example,
if memory was allocated using
\function
{
Py
Object
_
Malloc()
}
, it has to
be freed using
\function
{
PyObject
_
Free()
}
, not
\function
{
free()
}
. A
few modules included with Python fell afoul of this and had to be
fixed; doubtless there are more third-party modules that will have th
e
same
problem.
As part of this change, the confusing multiple interfaces for
allocating memory have been consolidated down into two APIs.
Memory allocated with one API must not be freed with the other API.
allocating memory have been consolidated down into two API families.
Memory allocated with one family must not be manipulated with
functions from the other family.
There is another family of functions specifically for allocating
Python
\emph
{
objects
}
(as opposed to memory).
\begin{itemize}
\item
To allocate and free an undistinguished chunk of memory using
Python's allocator, use
\cfunction
{
PyMem
_
Malloc()
}
,
\cfunction
{
PyMem
_
Realloc()
}
, and
\cfunction
{
PyMem
_
Free()
}
.
\item
In rare cases you may want to avoid using Python's allocator
in order to allocate a chunk of memory;
use
\cfunction
{
PyObject
_
Malloc
}
,
\cfunction
{
PyObject
_
Realloc
}
,
and
\cfunction
{
PyObject
_
Free
}
.
\item
To allocate and free Python objects,
use
\cfunction
{
PyObject
_
New()
}
,
\cfunction
{
PyObject
_
NewVar()
}
, and
\cfunction
{
PyObject
_
Del()
}
.
\item
To allocate and free an undistinguished chunk of memory use
the ``raw memory'' family:
\cfunction
{
PyMem
_
Malloc()
}
,
\cfunction
{
PyMem
_
Realloc()
}
, and
\cfunction
{
PyMem
_
Free()
}
.
\item
The ``object memory'' family is the interface to the pymalloc
facility described above and is biased towards a large number of
``small'' allocations:
\cfunction
{
PyObject
_
Malloc
}
,
\cfunction
{
PyObject
_
Realloc
}
, and
\cfunction
{
PyObject
_
Free
}
.
\item
To allocate and free Python objects, use the ``object'' family
\cfunction
{
PyObject
_
New()
}
,
\cfunction
{
PyObject
_
NewVar()
}
, and
\cfunction
{
PyObject
_
Del()
}
.
\end{itemize}
Thanks to lots of work by Tim Peters, pymalloc in 2.3 also provides
...
...
@@ -412,6 +415,13 @@ both extension modules and in the interpreter itself. To enable this
support, turn on the Python interpreter's debugging code by running
\program
{
configure
}
with
\longprogramopt
{
with-pydebug
}
.
To aid extension writers, a header file
\file
{
Misc/pymemcompat.h
}
is
distributed with the source to Python 2.3 that allows Python
extensions to use the 2.3 interfaces to memory allocation and compile
against any version of Python since 1.5.2. (The idea is that you take
the file from Python's source distribution and bundle it with the
source of you extension).
\begin{seealso}
\seeurl
{
http://cvs.sourceforge.net/cgi-bin/viewcvs.cgi/python/python/dist/src/Objects/obmalloc.c
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment