summary refs log tree commit diff stats
diff options
context:
space:
mode:
-rw-r--r--doc/gc.txt17
-rw-r--r--lib/impure/db_sqlite.nim6
2 files changed, 21 insertions, 2 deletions
diff --git a/doc/gc.txt b/doc/gc.txt
index 13498afaa..18fb03b6d 100644
--- a/doc/gc.txt
+++ b/doc/gc.txt
@@ -107,3 +107,20 @@ that up to 100 objects are traversed and freed before it checks again. Thus
 ``workPackage`` affects the timing granularity and may need to be tweaked in
 highly specialized environments or for older hardware.
 
+
+Keeping track of memory
+-----------------------
+
+If you need to pass around memory allocated by Nimrod to C, you can use the
+procs ``GC_ref`` and ``GC_unref`` to mark objects as referenced to avoid them
+being freed by the GC. Other useful procs from `system <system.html>`_ you can
+use to keep track of memory are:
+
+* getTotalMem(): returns the amount of total memory managed by the GC.
+* getOccupiedMem(): bytes reserved by the GC and used by objects.
+* getFreeMem(): bytes reserved by the GC and not in use.
+
+In addition to ``GC_ref`` and ``GC_unref`` you can avoid the GC by manually
+allocating memory with procs like ``alloc``, ``allocShared``, or
+``allocCStringArray``. The GC won't try to free them, you need to call their
+respective *dealloc* pairs when you are done with them or they will leak.
diff --git a/lib/impure/db_sqlite.nim b/lib/impure/db_sqlite.nim
index a3499a6df..809ee7039 100644
--- a/lib/impure/db_sqlite.nim
+++ b/lib/impure/db_sqlite.nim
@@ -148,7 +148,8 @@ proc getValue*(db: TDbConn, query: TSqlQuery,
   if finalize(stmt) != SQLITE_OK: dbError(db)
   
 proc tryInsertID*(db: TDbConn, query: TSqlQuery, 
-                  args: varargs[string, `$`]): int64 {.tags: [FWriteDb].} =
+                  args: varargs[string, `$`]): int64
+                  {.tags: [FWriteDb], raises: [].} =
   ## executes the query (typically "INSERT") and returns the 
   ## generated ID for the row or -1 in case of an error. 
   var q = dbFormat(query, args)
@@ -157,7 +158,8 @@ proc tryInsertID*(db: TDbConn, query: TSqlQuery,
   if prepare_v2(db, q, q.len.cint, stmt, nil) == SQLITE_OK:
     if step(stmt) == SQLITE_DONE:
       result = last_insert_rowid(db)
-  if finalize(stmt) != SQLITE_OK: dbError(db)
+    if finalize(stmt) != SQLITE_OK:
+      result = -1
 
 proc insertID*(db: TDbConn, query: TSqlQuery, 
                args: varargs[string, `$`]): int64 {.tags: [FWriteDb].} =