open arrays documented in the manual

This commit is contained in:
Araq 2013-02-10 15:06:25 +01:00
commit 3d7abb958d
5 changed files with 38 additions and 6 deletions

View file

@ -72,7 +72,7 @@ proc HandleCmdLine() =
when defined(GC_setMaxPause):
GC_setMaxPause 2_000
when compileOption("gc", "v2"):
when compileOption("gc", "v2") or compileOption("gc", "refc"):
# the new correct mark&sweet collector is too slow :-/
GC_disableMarkAndSweep()
condsyms.InitDefines()

View file

@ -911,7 +911,21 @@ Arrays are always bounds checked (at compile-time or at runtime). These
checks can be disabled via pragmas or invoking the compiler with the
``--boundChecks:off`` command line switch.
The current implementation does not support nested open arrays.
Open arrays
-----------
Often fixed size arrays turn out to be too inflexible; procedures should
be able to deal with arrays of different sizes. The `openarray`:idx: type
allows this; it can only be used for parameters. Openarrays are always
indexed with an ``int`` starting at position 0. The ``len``, ``low``
and ``high`` operations are available for open arrays too. Any array with
a compatible base type can be passed to an openarray parameter, the index
type does not matter. In addition to arrays sequences can also be passed
to an open array parameter.
The openarray type cannot be nested: multidimensional openarrays are not
supported because this is seldom needed and cannot be done efficiently.
Varargs

View file

@ -18,6 +18,9 @@
# for soft real time applications (like games).
{.push profiler:off.}
# XXX there is still a slight chance of leaking cycles as we don't add cycle
# candidates in 'incRef'
const
CycleIncrease = 2 # is a multiplicative increase
InitialCycleThreshold = 4*1024*1024 # X MB because cycle checking is slow
@ -33,7 +36,6 @@ when defined(memProfiler):
const
rcIncrement = 0b1000 # so that lowest 3 bits are not touched
# NOTE: Most colors are currently unused
rcBlack = 0b000 # cell is colored black; in use or free
rcGray = 0b001 # possible member of a cycle
rcWhite = 0b010 # member of a garbage cycle

View file

@ -5,37 +5,51 @@ discard """
type
Module = object
nodes*: seq[PNode]
id: int
PModule = ref Module
Node = object
owner*: PModule
data*: array[0..200, char] # some fat to drain memory faster
id: int
PNode = ref Node
var
gid: int
when false:
proc finalizeNode(x: PNode) =
echo "node id: ", x.id
proc finalizeModule(x: PModule) =
echo "module id: ", x.id
proc newNode(owner: PModule): PNode =
new(result)
result.owner = owner
inc gid
result.id = gid
proc compileModule: PModule =
new(result)
result.nodes = @[]
for i in 0..100:
result.nodes.add newNode(result)
inc gid
result.id = gid
var gModuleCache: PModule
proc loop =
for i in 0..10000:
for i in 0..1000:
gModuleCache = compileModule()
gModuleCache = nil
GC_fullCollect()
if getOccupiedMem() > 900_000:
if getOccupiedMem() > 9_000_000:
echo "still a leak! ", getOccupiedMem()
quit(1)
echo "no leak: ", getOccupiedMem()
loop()

View file

@ -4,6 +4,8 @@ version 0.9.2
- implement constructors + full 'not nil' checking
- ``restrict`` pragma + backend support
- fix: 'result' is not properly cleaned for NRVO
- document NimMain and check whether it works for threading
version 0.9.4
=============