# Memory cost expensive for SketchUp C API

**URL:** <https://forums.sketchup.com/t/memory-cost-expensive-for-sketchup-c-api/7625>\
**Category:** SketchUp SDK\
**Created:** [February 26, 2015, 9:52am UTC](https://forums.sketchup.com/t/memory-cost-expensive-for-sketchup-c-api/7625 "2015-02-26T09:52:32Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![justinwhp](https://avatars.discourse-cdn.com/v4/letter/j/c77e96/32.png) [@justinwhp](https://forums.sketchup.com/u/justinwhp)\
**Post date:** [February 26, 2015, 9:52am UTC](https://forums.sketchup.com/t/memory-cost-expensive-for-sketchup-c-api/7625/1 "2015-02-26T09:52:32Z")

</div>

Hi Expert,

There are 484471 faces in the created SketchUp model. I don’t attach this model because its size is 80M. I just share it here “\\shacng109wqm5\share\perf\13-00 asm\_1.skp”.

From the following result when create this SketchUp model, we can see the peak memory cost( **364M** and **520M** ) happened in the SketchUp API is expensive. I want to know whether the memory cost is as designed or not.

I am just curious why calling SUEntitiesFill(…) costs 520M. From my point of view, all faces have been added into the geometry input.

1. **Add all faces into SUGeometryInputRef object by following SketchUp API** : **cost**  **364M**  
SULoopInputCreate(SULoopInputRef\* loop\_input)  
SUGeometryInputAddVertex(SUGeometryInputRef geom\_input, const struct SUPoint3D\* point)  
SULoopInputAddVertexIndex(SULoopInputRef loop\_input, size\_t vertex\_index)  
SUGeometryInputAddFace(SUGeometryInputRef geom\_input, SULoopInputRef\* outer\_loop, size\_t\* added\_face\_index)

2. **Add SUGeometryInputRef object into model by the following API: cost 520M**  
SUEntitiesFill(SUEntitiesRef entities, SUGeometryInputRef geom\_input, true)

---

<div class="post-metadata">

**Author:** ![Geo](https://sea2.discourse-cdn.com/sketchup/user_avatar/forums.sketchup.com/geo/32/82_2.png) [@Geo](https://forums.sketchup.com/u/Geo)\
**Post date:** [February 26, 2015, 3:34pm UTC](https://forums.sketchup.com/t/memory-cost-expensive-for-sketchup-c-api/7625/2 "2015-02-26T15:34:09Z")

</div>

> [@justinwhp](#):
>
> I just share it here “\shacng109wqm5\share\perf\13-00 asm\_1.skp”.

The link does not work.

---

<div class="post-metadata">

**Author:** ![bugra](https://sea2.discourse-cdn.com/sketchup/user_avatar/forums.sketchup.com/bugra/32/33481_2.png) [@bugra](https://forums.sketchup.com/u/bugra)\
**Post date:** [February 26, 2015, 7:11pm UTC](https://forums.sketchup.com/t/memory-cost-expensive-for-sketchup-c-api/7625/3 "2015-02-26T19:11:03Z")

</div>

SUGeometryInput just holds some temporary data structures to be used as input to SUEntitiesFill, which then takes this input and turns it into actual internal SketchUp data structures. After the call, you need to delete the geometry input object but you’ll still have all the geometry in the model. What’s the memory usage after that?

---

<div class="post-metadata">

**Author:** ![justinwhp](https://avatars.discourse-cdn.com/v4/letter/j/c77e96/32.png) [@justinwhp](https://forums.sketchup.com/u/justinwhp)\
**Post date:** [February 27, 2015, 9:38am UTC](https://forums.sketchup.com/t/memory-cost-expensive-for-sketchup-c-api/7625/4 "2015-02-27T09:38:49Z")

</div>

For Geo, sorry for the link. If you still need the model, I will send you by other way later.

For bugra, I can assume that calling SUEntitiesFill(…) should cause one copy for all temporary data structures in SUGeometryInput, am I correct? Even if so, there is still **156M** (520M-364M) more memory cost when calling SUEntitiesFill(…). Is there other operation to cost 156M more memory?

In addition, I also call SUGeometryInputRelease(…) for SUGeometryInput. It does release **271M**. But there is still **93M** (364M-271M) not released. Is there any memory leak here?

---

<div class="post-metadata">

**Author:** ![Geo](https://sea2.discourse-cdn.com/sketchup/user_avatar/forums.sketchup.com/geo/32/82_2.png) [@Geo](https://forums.sketchup.com/u/Geo)\
**Post date:** [February 27, 2015, 11:55am UTC](https://forums.sketchup.com/t/memory-cost-expensive-for-sketchup-c-api/7625/5 "2015-02-27T11:55:58Z")

</div>

> [@justinwhp](#):
>
> For Geo, sorry for the link. If you still need the model, I will send you by other way later.

By all means please do.  
Curious how 484,471 faces = 80MB

---

<div class="post-metadata">

**Author:** ![bugra](https://sea2.discourse-cdn.com/sketchup/user_avatar/forums.sketchup.com/bugra/32/33481_2.png) [@bugra](https://forums.sketchup.com/u/bugra)\
**Post date:** [February 27, 2015, 3:45pm UTC](https://forums.sketchup.com/t/memory-cost-expensive-for-sketchup-c-api/7625/6 "2015-02-27T15:45:45Z")

</div>

> [@justinwhp](#):
>
> In addition, I also call SUGeometryInputRelease(…) for SUGeometryInput. It does release 271M. But there is still 93M(364M-271M) not released. Is there any memory leak here?

Interesting. I would be surprised if there is a memory leak because it just uses regular std::vector storage internally. But I’ll double check.

---

<div class="post-metadata">

**Author:** ![bugra](https://sea2.discourse-cdn.com/sketchup/user_avatar/forums.sketchup.com/bugra/32/33481_2.png) [@bugra](https://forums.sketchup.com/u/bugra)\
**Post date:** [February 27, 2015, 4:01pm UTC](https://forums.sketchup.com/t/memory-cost-expensive-for-sketchup-c-api/7625/7 "2015-02-27T16:01:30Z")

</div>

> [@justinwhp](#):
>
> For bugra, I can assume that calling SUEntitiesFill(…) should cause one copy for all temporary data structures in SUGeometryInput, am I correct? Even if so, there is still 156M(520M-364M) more memory cost when calling SUEntitiesFill(…). Is there other operation to cost 156M more memory?

It’s not really a copy, it takes rudimentary input data structures (i.e. SUGeometryInputRef) and turns it into real SketchUp data structures. It is hard to say whether 156MB is warranted for the model you are looking at. Data structures are pretty complicated.

---

<div class="post-metadata">

**Author:** ![skapp](https://avatars.discourse-cdn.com/v4/letter/s/b5e925/32.png) [@skapp](https://forums.sketchup.com/u/skapp)\
**Post date:** [June 9, 2015, 5:59pm UTC](https://forums.sketchup.com/t/memory-cost-expensive-for-sketchup-c-api/7625/8 "2015-06-09T17:59:06Z")

</div>

I’m not sure if I am having the same issue or not. But I have noticed that when using SUEntitiesFill in windows 8, it is a lot slower than windows 7. I create a vector of SUGeometryInputRef, it has some 10,000 geo inputs. In windows 7 it takes less than 3 seconds. In windows 8 it takes a little over 30 seconds! Any thoughts?

```
    SUEntitiesRef entities = SU_INVALID;
    SUModelGetEntities(model, &entities);
    
    size_t count = geo_input.size();
    
    for(size_t i=0; i < count; i++){
    	SUEntitiesFill(entities, geo_input[i], true);
    }

```

@bugra @tt_su

---

<div class="post-metadata">

**Author:** ![bugra](https://sea2.discourse-cdn.com/sketchup/user_avatar/forums.sketchup.com/bugra/32/33481_2.png) [@bugra](https://forums.sketchup.com/u/bugra)\
**Post date:** [June 9, 2015, 8:53pm UTC](https://forums.sketchup.com/t/memory-cost-expensive-for-sketchup-c-api/7625/9 "2015-06-09T20:53:22Z")

</div>

We had some reports of such slowdowns with certain virus protection programs. Can you try again with it disabled?

---

<div class="post-metadata">

**Author:** ![skapp](https://avatars.discourse-cdn.com/v4/letter/s/b5e925/32.png) [@skapp](https://forums.sketchup.com/u/skapp)\
**Post date:** [June 9, 2015, 9:06pm UTC](https://forums.sketchup.com/t/memory-cost-expensive-for-sketchup-c-api/7625/10 "2015-06-09T21:06:46Z")

</div>

I just did. It was the Windows Defender that is slowing it down. Thanks!

---

<div class="post-metadata">

**Author:** ![skapp](https://avatars.discourse-cdn.com/v4/letter/s/b5e925/32.png) [@skapp](https://forums.sketchup.com/u/skapp)\
**Post date:** [June 10, 2015, 9:19pm UTC](https://forums.sketchup.com/t/memory-cost-expensive-for-sketchup-c-api/7625/11 "2015-06-10T21:19:28Z")

</div>

So…what is the work around with something like that, other than disabling it or adding sketchup.exe to the protection program. Is there anything I can add in my code that will work around this?

---

<div class="post-metadata">

**Author:** ![bugra](https://sea2.discourse-cdn.com/sketchup/user_avatar/forums.sketchup.com/bugra/32/33481_2.png) [@bugra](https://forums.sketchup.com/u/bugra)\
**Post date:** [June 11, 2015, 1:38am UTC](https://forums.sketchup.com/t/memory-cost-expensive-for-sketchup-c-api/7625/12 "2015-06-11T01:38:01Z")

</div>

We don’t have a viable workaround at the moment but we have the issue logged. We haven’t yet had luck duplicating such dramatic slow downs.
