Skip to content

How to estimate the size of a hoc object from Python? #2085

Answered by nrnhines
WeinaJi asked this question in Q&A
Discussion options

You must be logged in to vote

Perhaps h.nrn_malinfo(1) can help. (missing from nrn.readthedocs.io but see the end of nrn/src/oc/symbol.cpp)
The return values just need a bit of thoughtful interpretation, e.g.

hines@michaels-macbook-pro-2 oc % cat temp.py
from neuron import h

def make_vectors(nvec, nsize):
    memsize_begin = h.nrn_mallinfo(1)
    print("memsize_begin ", memsize_begin)
    vectors = [h.Vector(nsize) for _ in range(nvec)]
    memsize = h.nrn_mallinfo(1) - memsize_begin
    print("{} vectors of size {} using {} bytes".format(nvec, nsize, memsize))
    del vectors

make_vectors(100, 0)
make_vectors(100, 10)
make_vectors(100, 100)
make_vectors(100, 1000)

hines@michaels-macbook-pro-2 oc % for i in 1 2 3 4…

Replies: 2 comments

Comment options

You must be logged in to vote
0 replies
Answer selected by alexsavulescu
Comment options

WeinaJi
Nov 11, 2022
Collaborator Author

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants
Converted from issue

This discussion was converted from issue #2075 on November 12, 2022 16:38.