Is there a function that will take a memory address and see if it is in use? I need to know so that a function I'm writing can tell if a "long" is a number, or a location of a string.
Printable View
Is there a function that will take a memory address and see if it is in use? I need to know so that a function I'm writing can tell if a "long" is a number, or a location of a string.
alloc is very implementation specific, so in short - the answer is no. Now you could hack your alloc functions to see how they are implemented on your system and then use that to find a solution to your problem, but it wouldn't be easy.
Now the fact that you are asking this question in the first place means that you have a design problem somewhere in your program. When malloc is called, you are the one which specifies how much memory to set aside, therefore if you need to know this size in the future - come up wich a mechanism of storing the memory size somewhere. It could be something as simple as:
Code:typedef struct _memloc
{
unsigned char* pmem;
size_t memsize;
} memloc, *pmemloc;
It's not my design problem, it's a problem in problem NerveBreak (http://nervebreak.sf.net/). I'm just trying to find a way around it.
Or why not implement a type variable so instead of guessing you can tell for sure?
Try reading it and if you seg fault then you know you aren't allowed to use it :)
good idea: I'll try to see if I can implement that in NerveBreak.Quote:
Originally Posted by itsme86
of course reading invalid memory doesn't always result in a seg fault either :)
Nervebreak appears to be opensource. It would be far easier to fix the problem there, than doing some hack in your own code.
That's worse than myQuote:
Originally Posted by Thantos
advice! :pCode:#define JLKJWERSDFDF std::cout