本文整理汇总了Python中pypy.rpython.memory.gc.semispace.SemiSpaceGC.malloc_varsize_clear方法的典型用法代码示例。如果您正苦于以下问题:Python SemiSpaceGC.malloc_varsize_clear方法的具体用法?Python SemiSpaceGC.malloc_varsize_clear怎么用?Python SemiSpaceGC.malloc_varsize_clear使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pypy.rpython.memory.gc.semispace.SemiSpaceGC
的用法示例。
在下文中一共展示了SemiSpaceGC.malloc_varsize_clear方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: coalloc_varsize_clear
# 需要导入模块: from pypy.rpython.memory.gc.semispace import SemiSpaceGC [as 别名]
# 或者: from pypy.rpython.memory.gc.semispace.SemiSpaceGC import malloc_varsize_clear [as 别名]
def coalloc_varsize_clear(self, coallocator, typeid,
length, size, itemsize,
offset_to_length):
if self.is_in_nursery(coallocator):
return self.malloc_varsize_clear(typeid, length, size, itemsize,
offset_to_length, True, False)
else:
return SemiSpaceGC.malloc_varsize_clear(self, typeid, length, size,
itemsize, offset_to_length,
True, False)
示例2: malloc_varsize_clear
# 需要导入模块: from pypy.rpython.memory.gc.semispace import SemiSpaceGC [as 别名]
# 或者: from pypy.rpython.memory.gc.semispace.SemiSpaceGC import malloc_varsize_clear [as 别名]
def malloc_varsize_clear(self, typeid, length, size, itemsize,
offset_to_length, can_collect,
has_finalizer=False):
# Only use the nursery if there are not too many items.
if not raw_malloc_usage(itemsize):
too_many_items = False
else:
# The following line is usually constant-folded because both
# min_nursery_size and itemsize are constants (the latter
# due to inlining).
maxlength_for_minimal_nursery = (self.min_nursery_size // 4 //
raw_malloc_usage(itemsize))
# The actual maximum length for our nursery depends on how
# many times our nursery is bigger than the minimal size.
# The computation is done in this roundabout way so that
# only the only remaining computation is the following
# shift.
maxlength = maxlength_for_minimal_nursery << self.nursery_scale
too_many_items = length > maxlength
if (has_finalizer or not can_collect or
too_many_items or
(raw_malloc_usage(size) > self.lb_young_var_basesize and
raw_malloc_usage(size) > self.largest_young_var_basesize)):
# ^^^ we do two size comparisons; the first one appears redundant,
# but it can be constant-folded if 'size' is a constant; then
# it almost always folds down to False, which kills the
# second comparison as well.
return SemiSpaceGC.malloc_varsize_clear(self, typeid, length, size,
itemsize, offset_to_length,
can_collect, has_finalizer)
# with the above checks we know now that totalsize cannot be more
# than about half of the nursery size; in particular, the + and *
# cannot overflow
size_gc_header = self.gcheaderbuilder.size_gc_header
totalsize = size_gc_header + size + itemsize * length
result = self.nursery_free
if raw_malloc_usage(totalsize) > self.nursery_top - result:
result = self.collect_nursery()
llarena.arena_reserve(result, totalsize)
# GCFLAG_NO_YOUNG_PTRS is never set on young objs
self.init_gc_object(result, typeid, flags=0)
(result + size_gc_header + offset_to_length).signed[0] = length
self.nursery_free = result + llarena.round_up_for_allocation(totalsize)
return llmemory.cast_adr_to_ptr(result+size_gc_header, llmemory.GCREF)
示例3: malloc_varsize_clear
# 需要导入模块: from pypy.rpython.memory.gc.semispace import SemiSpaceGC [as 别名]
# 或者: from pypy.rpython.memory.gc.semispace.SemiSpaceGC import malloc_varsize_clear [as 别名]
def malloc_varsize_clear(self, typeid, length, size, itemsize,
offset_to_length, can_collect,
has_finalizer=False):
if has_finalizer or not can_collect:
return SemiSpaceGC.malloc_varsize_clear(self, typeid, length, size,
itemsize, offset_to_length,
can_collect, has_finalizer)
size_gc_header = self.gcheaderbuilder.size_gc_header
nonvarsize = size_gc_header + size
# Compute the maximal length that makes the object still
# below 'nonlarge_max'. All the following logic is usually
# constant-folded because self.nonlarge_max, size and itemsize
# are all constants (the arguments are constant due to
# inlining) and self.has_gcptr_in_varsize() is constant-folded.
if self.has_gcptr_in_varsize(typeid):
nonlarge_max = self.nonlarge_gcptrs_max
else:
nonlarge_max = self.nonlarge_max
if not raw_malloc_usage(itemsize):
too_many_items = raw_malloc_usage(nonvarsize) > nonlarge_max
else:
maxlength = nonlarge_max - raw_malloc_usage(nonvarsize)
maxlength = maxlength // raw_malloc_usage(itemsize)
too_many_items = length > maxlength
if not too_many_items:
# With the above checks we know now that totalsize cannot be more
# than 'nonlarge_max'; in particular, the + and * cannot overflow.
# Let's try to fit the object in the nursery.
totalsize = nonvarsize + itemsize * length
result = self.nursery_free
if raw_malloc_usage(totalsize) <= self.nursery_top - result:
llarena.arena_reserve(result, totalsize)
# GCFLAG_NO_YOUNG_PTRS is never set on young objs
self.init_gc_object(result, typeid, flags=0)
(result + size_gc_header + offset_to_length).signed[0] = length
self.nursery_free = result + llarena.round_up_for_allocation(
totalsize)
return llmemory.cast_adr_to_ptr(result+size_gc_header,
llmemory.GCREF)
return self.malloc_varsize_slowpath(typeid, length)