Advertisement
Guest User

Untitled

a guest
Sep 29th, 2010
150
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.64 KB | None | 0 0
  1. #!/usr/bin/python
  2.  
  3. # $Id: malloc.py 1432 2010-09-29 10:13:16Z santi $
  4.  
  5. import sys
  6.  
  7. # Python >= 2.5 incluye la libreria *ctypes* el core, comprobar que esta disponible
  8. try:
  9.         from ctypes import CDLL
  10.  
  11. except ImportError:
  12.         print 'ERROR! La libreria *ctypes* para Python no esta disponible!'
  13.         sys.exit(-1)
  14.  
  15.  
  16.  
  17. libc = CDLL('libc.so.6')
  18. n = 0
  19.  
  20. while True:
  21.         n = n + 1
  22.         p = libc.malloc(n * 1024 * 1024)
  23.  
  24.         if p:
  25.                 print '%d MB' % n
  26.                 libc.free(p)
  27.  
  28.         else:
  29.                 print 'Limite de memoria alcanzado para malloc() => %d MB' % n
  30.                 sys.exit(-1)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement