# Memory allocation binary vs. weighted graphs

**URL:** <https://igraph.discourse.group/t/memory-allocation-binary-vs-weighted-graphs/1743>\
**Category:** Usage\
**Tags:** Python\
**Created:** [6 February 2024 12:05 UTC](https://igraph.discourse.group/t/memory-allocation-binary-vs-weighted-graphs/1743 "2024-02-06T12:05:26Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![amesse](https://avatars.discourse-cdn.com/v4/letter/a/8baadc/32.png) [@amesse](https://igraph.discourse.group/u/amesse)\
**Post date:** [6 February 2024 12:05 UTC](https://igraph.discourse.group/t/memory-allocation-binary-vs-weighted-graphs/1743/1 "2024-02-06T12:05:26Z")

</div>

I am using python-igraph and I need to know the memory footprint of a graph depending on whether it is weighted or not, any tip?  
thanks!

---

<div class="post-metadata">

**Author:** ![szhorvat](https://yyz2.discourse-cdn.com/free1/user_avatar/igraph.discourse.group/szhorvat/32/3_2.png) [@szhorvat](https://igraph.discourse.group/u/szhorvat)\
**Post date:** [6 February 2024 14:21 UTC](https://igraph.discourse.group/t/memory-allocation-binary-vs-weighted-graphs/1743/2 "2024-02-06T14:21:57Z")

</div>

“Weights” are just another edge attribute. Adding any numerical edge attribute consumes memory that takes linear space in the number of edges.

The memory used by the C representation of a graph takes (4m+2n)s bytes where m is the vertex count, n is the edge count, and s is the size of an integer on your platform. Usually s=8 on 64-bit platforms and s=4 on 32-bit ones. There is some additional fixed-space bookkeeping data, plus the attribute storage.

---

<div class="post-metadata">

**Author:** ![amesse](https://avatars.discourse-cdn.com/v4/letter/a/8baadc/32.png) [@amesse](https://igraph.discourse.group/u/amesse)\
**Post date:** [6 February 2024 20:04 UTC](https://igraph.discourse.group/t/memory-allocation-binary-vs-weighted-graphs/1743/3 "2024-02-06T20:04:42Z")

</div>

Thanks! Does it mean that for a weighted graph (4m+2n)s + nt, where t is the size of an attribute? How can we know this size? in my case, weights are positive floating numbers loaded from a ncol file.

---

<div class="post-metadata">

**Author:** ![szhorvat](https://yyz2.discourse-cdn.com/free1/user_avatar/igraph.discourse.group/szhorvat/32/3_2.png) [@szhorvat](https://igraph.discourse.group/u/szhorvat)\
**Post date:** [6 February 2024 21:08 UTC](https://igraph.discourse.group/t/memory-allocation-binary-vs-weighted-graphs/1743/4 "2024-02-06T21:08:21Z")

</div>

In C, t would be 8. Note that’s 8 times the edge count, not vertex count, assuming you are talking about edge weights.

In Python, I’m not sure. The person who could answer this definitively is away for a while. I believe in Python the attributes are stored as a plain Python list. So, the answer would be however much the list of weights takes up in Python.
