Thread: Checking for memory allocation...

  1. #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

  2. #2
    Registered User
    Join Date
    Sep 2004
    Location
    California
    Posts
    3,268
    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;

  3. #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

  4. #4
    Gawking at stupidity
    Join Date
    Jul 2004
    Location
    Oregon, USA
    Posts
    3,218
    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.

  5. #5
    & the hat of GPL slaying Thantos's Avatar
    Join Date
    Sep 2001
    Posts
    5,681
    Try reading it and if you seg fault then you know you aren't allowed to use it

  6. #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

  7. #7
    Registered User
    Join Date
    Sep 2004
    Location
    California
    Posts
    3,268
    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.

  8. #8
    UT2004 Addict Kleid-0's Avatar
    Join Date
    Dec 2004
    Posts
    656
    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!

Popular pages Recent additions subscribe to a feed

Similar Threads

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