open arrays documented in the manual
This commit is contained in:
parent
0bb3731422
commit
3d7abb958d
5 changed files with 38 additions and 6 deletions
|
|
@ -72,7 +72,7 @@ proc HandleCmdLine() =
|
||||||
when defined(GC_setMaxPause):
|
when defined(GC_setMaxPause):
|
||||||
GC_setMaxPause 2_000
|
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 :-/
|
# the new correct mark&sweet collector is too slow :-/
|
||||||
GC_disableMarkAndSweep()
|
GC_disableMarkAndSweep()
|
||||||
condsyms.InitDefines()
|
condsyms.InitDefines()
|
||||||
|
|
|
||||||
|
|
@ -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
|
checks can be disabled via pragmas or invoking the compiler with the
|
||||||
``--boundChecks:off`` command line switch.
|
``--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
|
Varargs
|
||||||
|
|
|
||||||
|
|
@ -18,6 +18,9 @@
|
||||||
# for soft real time applications (like games).
|
# for soft real time applications (like games).
|
||||||
{.push profiler:off.}
|
{.push profiler:off.}
|
||||||
|
|
||||||
|
# XXX there is still a slight chance of leaking cycles as we don't add cycle
|
||||||
|
# candidates in 'incRef'
|
||||||
|
|
||||||
const
|
const
|
||||||
CycleIncrease = 2 # is a multiplicative increase
|
CycleIncrease = 2 # is a multiplicative increase
|
||||||
InitialCycleThreshold = 4*1024*1024 # X MB because cycle checking is slow
|
InitialCycleThreshold = 4*1024*1024 # X MB because cycle checking is slow
|
||||||
|
|
@ -33,7 +36,6 @@ when defined(memProfiler):
|
||||||
|
|
||||||
const
|
const
|
||||||
rcIncrement = 0b1000 # so that lowest 3 bits are not touched
|
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
|
rcBlack = 0b000 # cell is colored black; in use or free
|
||||||
rcGray = 0b001 # possible member of a cycle
|
rcGray = 0b001 # possible member of a cycle
|
||||||
rcWhite = 0b010 # member of a garbage cycle
|
rcWhite = 0b010 # member of a garbage cycle
|
||||||
|
|
|
||||||
|
|
@ -5,37 +5,51 @@ discard """
|
||||||
type
|
type
|
||||||
Module = object
|
Module = object
|
||||||
nodes*: seq[PNode]
|
nodes*: seq[PNode]
|
||||||
|
id: int
|
||||||
|
|
||||||
PModule = ref Module
|
PModule = ref Module
|
||||||
|
|
||||||
Node = object
|
Node = object
|
||||||
owner*: PModule
|
owner*: PModule
|
||||||
data*: array[0..200, char] # some fat to drain memory faster
|
data*: array[0..200, char] # some fat to drain memory faster
|
||||||
|
id: int
|
||||||
|
|
||||||
PNode = ref Node
|
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 =
|
proc newNode(owner: PModule): PNode =
|
||||||
new(result)
|
new(result)
|
||||||
result.owner = owner
|
result.owner = owner
|
||||||
|
inc gid
|
||||||
|
result.id = gid
|
||||||
|
|
||||||
proc compileModule: PModule =
|
proc compileModule: PModule =
|
||||||
new(result)
|
new(result)
|
||||||
result.nodes = @[]
|
result.nodes = @[]
|
||||||
for i in 0..100:
|
for i in 0..100:
|
||||||
result.nodes.add newNode(result)
|
result.nodes.add newNode(result)
|
||||||
|
inc gid
|
||||||
|
result.id = gid
|
||||||
|
|
||||||
var gModuleCache: PModule
|
var gModuleCache: PModule
|
||||||
|
|
||||||
proc loop =
|
proc loop =
|
||||||
for i in 0..10000:
|
for i in 0..1000:
|
||||||
gModuleCache = compileModule()
|
gModuleCache = compileModule()
|
||||||
gModuleCache = nil
|
gModuleCache = nil
|
||||||
GC_fullCollect()
|
GC_fullCollect()
|
||||||
|
|
||||||
if getOccupiedMem() > 900_000:
|
if getOccupiedMem() > 9_000_000:
|
||||||
echo "still a leak! ", getOccupiedMem()
|
echo "still a leak! ", getOccupiedMem()
|
||||||
quit(1)
|
quit(1)
|
||||||
|
|
||||||
echo "no leak: ", getOccupiedMem()
|
echo "no leak: ", getOccupiedMem()
|
||||||
|
|
||||||
loop()
|
loop()
|
||||||
|
|
|
||||||
2
todo.txt
2
todo.txt
|
|
@ -4,6 +4,8 @@ version 0.9.2
|
||||||
- implement constructors + full 'not nil' checking
|
- implement constructors + full 'not nil' checking
|
||||||
- ``restrict`` pragma + backend support
|
- ``restrict`` pragma + backend support
|
||||||
- fix: 'result' is not properly cleaned for NRVO
|
- fix: 'result' is not properly cleaned for NRVO
|
||||||
|
- document NimMain and check whether it works for threading
|
||||||
|
|
||||||
|
|
||||||
version 0.9.4
|
version 0.9.4
|
||||||
=============
|
=============
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue