x86_64 환경에서 mallinfo() 함수로 malloc()한 크기를 구하려고 합니다.

ukyoukyo의 이미지

mallinfo() 함수로 동적할당된 메모리의 크기를 구하려고 합니다.

장비에 설치된 리눅스는 아래와 같습니다.

[root@SexyGirl:/root/MM] # uname -a
Linux SexyGirl 2.6.32-24-generic #38-Ubuntu SMP Mon Jul 5 09:20:59 UTC 2010 x86_64 GNU/Linux

64비트 리눅스라서 램을 4[GB] 장착했구요, 시스템은 아래와 같이 인식합니다.

[root@SexyGirl:/root/MM] # free -m
             total       used       free     shared    buffers     cached
Mem:     3951         570       3381             0            6            85
-/+ buffers/cache:  478      3473
Swap:         0             0           0

사용하려는 mallinfo 구조체는 아래와 같구요.

struct mallinfo
{
   int arena;    // non-mmapped space allocated from system
   int ordblks;  // number of free chunks
   int smblks;   // number of fastbin blocks
   int hblks;    // number of mmapped regions
   int hblkhd;   // space in mmapped regions
   int usmblks;  // maximum total allocated space
   int fsmblks;  // space available in freed fastbin blocks
   int uordblks; // total allocated space
   int fordblks; // total free space
   int keepcost; // top-most, releasable (via malloc_trim) space
};

위 멤버중에서 'ublkhd'가 malloc()하면 내부적으로 mmap()이 실행되어 증가되는 값으로 알고 있습니다.

#free -m의 결과중에 'free' 필드에서 나타내는 용량만큼(위 예제에서는 3381[MB]) malloc()한다고 가정하면,

RAM의 전체용량이 늘어나서 8[GB], 16[GB]가 되면 'free' 필드의 용량도 증가할텐데,

int ublkhd 변수로 표현할 수 있는 범위를 넘어서지 않는지요 ?




범위를 넘어선다면 어떻게 malloc()으로 할당된 사이즈를 파악할 수 있는지요 ? 이게 목적이긴합니다만.

동적할당된 메모리의 크기를 구하는 API나 방법은 없는지요 ?

mac040의 이미지

또 64bit를 위한 방법이 딱히 없다는 글도 있습니다.
HP-UX에서 같은 문제를 질문한 글과 답인데 다른 글을 찾아봐도 딱히 다른의견은 없는 것 같습니다.

http://forums11.itrc.hp.com/service/forums/questionanswer.do?threadId=943026

pastime의 이미지

malloc_stats, malloc_info 등을 사용할 수 있지만
파일 스트림에 쓰는 형태라 좀 불편할 수도 있습니다.

malloc 소스를 보면 malloc_get_state()를 이용할 수도 있겠습니다만
호환성 같은 건 전혀 고려할 수 없겠지요..
(위의 API도 어차피 호환되지는 않을 수 있겠군요.. ;;)

여기도 참조해 보세요.. ;;
http://studyfoss.egloos.com/5209389

ukyoukyo의 이미지


답변감사합니다.

malloc_stats() 의 소소를 한번 뒤져봐야 겠네요...

------------------ System programmer...^^


------------------ System programmer...^^

댓글 달기

Filtered HTML

  • 텍스트에 BBCode 태그를 사용할 수 있습니다. URL은 자동으로 링크 됩니다.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>
  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.

BBCode

  • 텍스트에 BBCode 태그를 사용할 수 있습니다. URL은 자동으로 링크 됩니다.
  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param>
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.

Textile

  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • You can use Textile markup to format text.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>

Markdown

  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • Quick Tips:
    • Two or more spaces at a line's end = Line break
    • Double returns = Paragraph
    • *Single asterisks* or _single underscores_ = Emphasis
    • **Double** or __double__ = Strong
    • This is [a link](http://the.link.example.com "The optional title text")
    For complete details on the Markdown syntax, see the Markdown documentation and Markdown Extra documentation for tables, footnotes, and more.
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>

Plain text

  • HTML 태그를 사용할 수 없습니다.
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.
  • 줄과 단락은 자동으로 분리됩니다.
댓글 첨부 파일
이 댓글에 이미지나 파일을 업로드 합니다.
파일 크기는 8 MB보다 작아야 합니다.
허용할 파일 형식: txt pdf doc xls gif jpg jpeg mp3 png rar zip.
CAPTCHA
이것은 자동으로 스팸을 올리는 것을 막기 위해서 제공됩니다.