C Board  

Go Back   C Board > General Programming Boards > C Programming

Reply
 
LinkBack Thread Tools Display Modes
Old 12-22-2004, 02:22 PM   #1
Registered User
 
kinghajj's Avatar
 
Join Date: Jun 2003
Posts: 218
Checking for memory allocation...

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.
__________________
01011001 01101111 01110101 00100000 01110100 01101111 01101111 1101011 00100000 01110100 01101000 01101001 01110011 00100000 01101101 01110101 01100011 01101000 00100000 01110100 01101000 01101101 01100101 00100000 01110100 01101111 00100000 01110010 01100101 01100001 01100100 00100000 01011001 01101000 01101001 01110011 00111111 00100000 01000100 01100001 01101101 01101110 00100001 00000000
kinghajj is offline   Reply With Quote
Old 12-22-2004, 02:40 PM   #2
Registered User
 
Join Date: Sep 2004
Location: California
Posts: 3,020
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;
bithub is offline   Reply With Quote
Old 12-22-2004, 02:46 PM   #3
Registered User
 
kinghajj's Avatar
 
Join Date: Jun 2003
Posts: 218
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.
__________________
01011001 01101111 01110101 00100000 01110100 01101111 01101111 1101011 00100000 01110100 01101000 01101001 01110011 00100000 01101101 01110101 01100011 01101000 00100000 01110100 01101000 01101101 01100101 00100000 01110100 01101111 00100000 01110010 01100101 01100001 01100100 00100000 01011001 01101000 01101001 01110011 00111111 00100000 01000100 01100001 01101101 01101110 00100001 00000000
kinghajj is offline   Reply With Quote
Old 12-22-2004, 02:47 PM   #4
Gawking at stupidity
 
Join Date: Jul 2004
Posts: 2,324
Or why not implement a type variable so instead of guessing you can tell for sure?
__________________
If you understand what you're doing, you're not learning anything.

Ignore any "advice" esbo tries to give you. It's wrong.
itsme86 is offline   Reply With Quote
Old 12-22-2004, 03:05 PM   #5
& the hat of GPL slaying
 
Thantos's Avatar
 
Join Date: Sep 2001
Posts: 5,732
Try reading it and if you seg fault then you know you aren't allowed to use it
Thantos is offline   Reply With Quote
Old 12-22-2004, 03:10 PM   #6
Registered User
 
kinghajj's Avatar
 
Join Date: Jun 2003
Posts: 218
Quote:
Originally Posted by itsme86
Or why not implement a type variable so instead of guessing you can tell for sure?
good idea: I'll try to see if I can implement that in NerveBreak.
__________________
01011001 01101111 01110101 00100000 01110100 01101111 01101111 1101011 00100000 01110100 01101000 01101001 01110011 00100000 01101101 01110101 01100011 01101000 00100000 01110100 01101000 01101101 01100101 00100000 01110100 01101111 00100000 01110010 01100101 01100001 01100100 00100000 01011001 01101000 01101001 01110011 00111111 00100000 01000100 01100001 01101101 01101110 00100001 00000000
kinghajj is offline   Reply With Quote
Old 12-22-2004, 03:11 PM   #7
Registered User
 
Join Date: Sep 2004
Location: California
Posts: 3,020
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.
bithub is offline   Reply With Quote
Old 12-22-2004, 10:42 PM   #8
UT2004 Addict
 
Kleid-0's Avatar
 
Join Date: Dec 2004
Posts: 645
Quote:
Originally Posted by Thantos
Try reading it and if you seg fault then you know you aren't allowed to use it
That's worse than my
Code:
#define JLKJWERSDFDF std::cout
advice!
Kleid-0 is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
dynamic allocation from 1 instead of zero cfdprogrammer C Programming 27 04-28-2009 08:21 AM
Checking memory allocation JoeBloggs C Programming 5 12-09-2008 05:01 AM
Profiler Valgrind afflictedd2 C++ Programming 4 07-18-2008 09:38 AM
Interpreter.c moussa C Programming 4 05-28-2008 05:59 PM
Problems about gcc installation kevin_cat Linux Programming 4 08-09-2005 09:05 AM


All times are GMT -6. The time now is 09:13 AM.


Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.3.2

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22