MCPcopy Index your code
hub / github.com/python/cpython / malloc

Method malloc

Lib/multiprocessing/heap.py:296–316  ·  view source on GitHub ↗
(self, size)

Source from the content-addressed store, hash-verified

294 self._lock.release()
295
296 def malloc(self, size):
297 # return a block of right size (possibly rounded up)
298 if size < 0:
299 raise ValueError("Size {0:n} out of range".format(size))
300 if sys.maxsize <= size:
301 raise OverflowError("Size {0:n} too large".format(size))
302 if os.getpid() != self._lastpid:
303 self.__init__() # reinitialize after fork
304 with self._lock:
305 self._n_mallocs += 1
306 # allow pending blocks to be marked available
307 self._free_pending_blocks()
308 size = self._roundup(max(size, 1), self._alignment)
309 (arena, start, stop) = self._malloc(size)
310 real_stop = start + size
311 if real_stop < stop:
312 # if the returned block is larger than necessary, mark
313 # the remainder available
314 self._add_free_block((arena, real_stop, stop))
315 self._allocated_blocks[arena].add((start, real_stop))
316 return (arena, start, real_stop)
317
318#
319# Class wrapping a block allocated out of a Heap -- can be inherited by child process

Callers 1

__init__Method · 0.80

Calls 7

__init__Method · 0.95
_free_pending_blocksMethod · 0.95
_roundupMethod · 0.95
_mallocMethod · 0.95
_add_free_blockMethod · 0.95
formatMethod · 0.45
addMethod · 0.45

Tested by

no test coverage detected