Skip to content

Commit 728bd5d

Browse files
committed
Switched to caml_alloc_custom_mem
1 parent 8ab839f commit 728bd5d

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

src/postgresql_stubs.c

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -534,8 +534,17 @@ static struct custom_operations result_ops = {
534534

535535
static inline value alloc_result(PGresult *res, np_callback *cb)
536536
{
537-
value v_res =
538-
caml_alloc_custom(&result_ops, sizeof(struct pg_ocaml_result), 1, 100000);
537+
value v_res;
538+
size_t result_size, ocaml_result_size = sizeof(struct pg_ocaml_result);
539+
#if PG_OCAML_MAJOR_VERSION < 12
540+
/* There isn't really a bound on size here, it all depends on the number
541+
of records, columns, and type of data. 4096 bytes seems like a reasonable
542+
size that shouldn't lead to excessive GC pressure. */
543+
result_size = 4096;
544+
#else
545+
result_size = PQresultMemorySize(res);
546+
#endif
547+
v_res = caml_alloc_custom_mem(&result_ops, ocaml_result_size, result_size);
539548
set_res(v_res, res);
540549
set_res_cb(v_res, cb);
541550
np_incr_refcount(cb);

0 commit comments

Comments
 (0)