Thread: Memory dynamic allocation

  1. #1
    Registered User
    Join Date
    Oct 2007
    Posts
    6

    Memory dynamic allocation

    Hi guys.

    I'm trying alloc memory with malloc, but i am having problems.
    I need too much memory that malloc can alloc. I'm trying to use mmap too, but no sucess.
    Anybody can help me? I am using Debian GNU Linux.

    Thanks
    Elvio
    elvio.vicosa(at)gmail.com

  2. #2
    Deathray Engineer MacGyver's Avatar
    Join Date
    Mar 2007
    Posts
    3,210
    Post some short example code of what is failing. If you could give us a small test program that shows the issue that would be great.

  3. #3
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    Or perhaps state what problem you're trying to solve, and explain why you think you need so much memory in the first place.
    Then we might be able to suggest alternative strategies.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  4. #4
    Registered User
    Join Date
    Oct 2007
    Posts
    6
    Hi.

    My problem is that i must alloc a struct( double x, y) and a graph( int** )
    The problem is the "salesman problem", and sometimes i need to read and alloc 33,000 cities on the
    program. So, i can alloc ~3,000, after this i receive segmentation fault. The strace of my program show problem in malloc and gdb show that malloc can not alloc memory. I really need keep all data on the structs, because i will do calcs with them.

    After a read the data i need "walk" on graph, to get the shortest path. I am using a recursive algorithm, and each recursion need to alloc a vector( int*) that will hold the guest nodes of graph. So, i need much memory to keep all data "on fly". I tried to flush some data in files, but i need high performance.

    Will have at least n! allocation of int vector, where n is the number of cities. I have never need to alloc too memory, so i really do not know how to solve this problem.

    Thanks for all, and sorry for my english. I am brazilian and do not know english well(yet)

  5. #5
    Officially An Architect brewbuck's Avatar
    Join Date
    Mar 2007
    Location
    Portland, OR
    Posts
    7,396
    Sounds like you're corrupting memory somewhere.

  6. #6
    Deathray Engineer MacGyver's Avatar
    Join Date
    Mar 2007
    Posts
    3,210
    What brewbuck said.

  7. #7
    Registered User
    Join Date
    Oct 2007
    Posts
    36
    the very simple answer for the cause is MEMORY OVERFLOW...your server is not having enough memory to allocate...check out the below command and see how much memory are you left with...also POST the memory status and the part of your code which you are using to allocate memory...

    Code:
    $/sbin/fdisk -l
    this will definitely resolve your issue...

  8. #8
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    > $/sbin/fdisk -l
    What the hell has formatting the disk got to do with anything?

    @elvio.vicosa
    As well as taking up exponential memory, the TSP takes up exponential time as well. So even if you could allocate it all, you'd be long dead before any results were available.
    I would suggest further research on the problem, as there are I believe some techniques which can aggressively prune the search space to something far more manageable (in space and time).
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  9. #9
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    This seems "doomed to fail". If you have n! items to allocate, and n is 33000, I don't think all computers in the world would have sufficient memory to hold it.

    The amount of memory you can normally allocate with a Linux application is either 1GB or 3GB (assuming sufficient RAM + Swapspace of course). If you have a 64-bit system, then you'd be limited only by the amount of memory + swap-space.

    fdisk -l
    will list the current partitions of the drive, so it's harmless and will show what the swap size is, which would help us with the above answer of "how much swap-space" there is.

    Obviously the total available swap-space is distributed over the system, so if you have 1GB of RAM and 2GB of swap, the total amount of available allocation for the entire system is 3GB.

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. To find the memory leaks without using any tools
    By asadullah in forum C Programming
    Replies: 2
    Last Post: 05-12-2008, 07:54 AM
  2. Replies: 16
    Last Post: 01-01-2008, 04:07 PM
  3. Dynamic memory allocation.
    By HAssan in forum C Programming
    Replies: 3
    Last Post: 09-07-2006, 05:04 PM
  4. Dynamic memory allocation...
    By dicorr in forum C Programming
    Replies: 1
    Last Post: 06-24-2006, 03:59 AM
  5. pointers
    By InvariantLoop in forum C Programming
    Replies: 13
    Last Post: 02-04-2005, 09:32 AM