# HeapBlock malloc/calloc/realloc/allocate/free

**URL:** <https://forum.juce.com/t/heapblock-malloc-calloc-realloc-allocate-free/5416>\
**Category:** General JUCE discussion\
**Created:** [June 28, 2010, 10:04pm UTC](https://forum.juce.com/t/heapblock-malloc-calloc-realloc-allocate-free/5416 "2010-06-28T22:04:29Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Atrus](https://avatars.discourse-cdn.com/v4/letter/a/67e7ee/32.png) [@Atrus](https://forum.juce.com/u/Atrus)\
**Post date:** [June 28, 2010, 10:04pm UTC](https://forum.juce.com/t/heapblock-malloc-calloc-realloc-allocate-free/5416/1 "2010-06-28T22:04:29Z")

</div>

I’m running into an issue with HeapBlock malloc/calloc/realloc/allocate/free. We have our own memory debugger which defines its own versions of malloc etc., but juce\_HeapBlock.h undefines those macros in order to use the names for member functions. Wouldn’t it be wiser to just name the functions something else (like hb\_malloc) so that Juce doesn’t stomp on user defined malloc etc.?

---

<div class="post-metadata">

**Author:** ![dinaiz](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/dinaiz/32/182_2.png) [@dinaiz](https://forum.juce.com/u/dinaiz)\
**Post date:** [June 29, 2010, 5:34am UTC](https://forum.juce.com/t/heapblock-malloc-calloc-realloc-allocate-free/5416/2 "2010-06-29T05:34:18Z")

</div>

In C++, the standard solution to avoid name clashes is namespaces.

I noticed that, when you include \<juce.h\> there’s an “using namespace JUCE\_NAMESPACE;” added to your code. You can remove it by replacing

```auto

```

by

```auto
#define DONT_SET_USING_JUCE_NAMESPACE
#include <juce.h>
```

Maybe it’s worth a try ?

However, every reference to juce library will nbow have to be prefixed by juce:: which can be a pain in the neck if you have a lot of code

e.g. :

```auto

```

will have to become :

```auto

```

---

<div class="post-metadata">

**Author:** ![jules](https://avatars.discourse-cdn.com/v4/letter/j/41988e/32.png) [@jules](https://forum.juce.com/u/jules)\
**Post date:** [June 29, 2010, 8:52am UTC](https://forum.juce.com/t/heapblock-malloc-calloc-realloc-allocate-free/5416/3 "2010-06-29T08:52:22Z")

</div>

> [@](#):
>
> I’m running into an issue with HeapBlock malloc/calloc/realloc/allocate/free. We have our own memory debugger which defines its own versions of malloc etc., but juce\_HeapBlock.h undefines those macros in order to use the names for member functions. Wouldn’t it be wiser to just name the functions something else (like hb\_malloc) so that Juce doesn’t stomp on user defined malloc etc.?

The easy fix would presumably just be to include your own header after juce.h (or just to redefine those macros after including it). That’s pretty trivial to do.

But I’d recommend the smarter approach of spending an hour or two removing malloc and free from all your code, in favour of something like HeapBlock. That way, you’d probably no longer need a memory debugger at all…
