• C

Funtions to automatic allocate and deallocate memory.

Functions to allocate and deallocate automatic memory?

I have a group of functions that allocate and deallocate memory on demand. But fails in some cases to deallocate.
Some group of functions to make this in glibc or similar?
ZOOMPLUSAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

rajeev_devinCommented:
Put some examples.
0
WelkinMazeCommented:
Hi,
Maybe you reassign some pointer somewhere in between allocation and deallocation?
0
cryptosidCommented:
Hi,

I do not think there are any inbuilt automatic functions to auto allocate and deallocate in pure C.

C++ however provides you constructors and destructors which get called when you create and destroy objects.

your malloc and free() functions could be embedded in these constructors and destructors to ensure automatic allocation and deallocation.

Regards,
Siddhesh
0
Managing Security Policy in a Changing Environment

The enterprise network environment is evolving rapidly as companies extend their physical data centers to embrace cloud computing and software-defined networking. This new reality means that the challenge of managing the security policy is much more dynamic and complex.

ozoCommented:
0
ZOOMPLUSAuthor Commented:
I have some problems sometimes to realloc and free.
glibc. Linux.gcc

The pointer is the same, there is no problem here.
I do not know which is the problem.
0
rahul_r_jadhavCommented:
can you post the code??
0
grg99Commented:
Why do you think it's not deallocating?  

Many memory libraries keep a few memory blocks allocated at all times to handle the next allocation request.

0
ZOOMPLUSAuthor Commented:
glibc said fail, something like.

realloc next pointer fail, or free fail or something like this
0
grg99Commented:
You're probably writing past the end of a pointer.  Be sure all your array indices are in range, and not off by one.

Or maybe you're free()ing a pointer twice.

 
0
NopiusCommented:
Use realloc and remember, the pointer may be changed itself (it changes when data boundary grows/shrinks 4K*N size):
use:
p=realloc(p, new_size); // instead of //  realloc(p, new_size);

You don't need to use free(p) then realloc(p..), just realloc() as many times as you want
0
Dragon_KromeCommented:
Try running your program with valgrind or a memory allocation debugging tool (there are more of those, dmalloc is one for example).
They might help you catch the bug, because there's surely one ;)
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Dragon_KromeCommented:
also, you might try to compile with -fbounds-check if your compiler supports it
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
C

From novice to tech pro — start learning today.