忍者ブログ

なんだか

知らないほうが幸せかもしれない

[PR]

×

[PR]上記の広告は3ヶ月以上新規記事投稿のないブログに表示されています。新しい記事を書く事で広告が消えます。

gccのコンパイルが早くならないかな

gccが4.4の頃に見つけた方法なんです。

>通常、 malloc() は、ヒープからメモリを割り当て、必要に応じてヒープのサイズを sbrk(2) を使って調節する。

sbrkの呼び出しが多いとkernelの負荷が馬鹿にならないようです。

先に大量にmallocしておいて、開放しておけば、sbrkの呼び出しが減らせるのではと考えたわけです。

早くなってるかどうかはわからないが、sbrkの呼び出しは減ってるかな。

--- a/libiberty/xmalloc.c.1024 2005-05-25 06:01:33.000000000 +0900
+++ b/libiberty/xmalloc.c 2009-11-17 17:42:36.901024875 +0900
@@ -100,6 +100,30 @@ static const char *name = "";
/* The initial sbrk, set when the program name is set. Not used for win32
ports other than cygwin32. */
static char *first_break = NULL;
+static
+inline
+void
+check_first_break(void)
+{
+ if(first_break) return;
+ /* Win32 ports other than cygwin32 don't have brk() */
+ first_break = (char *) sbrk (0);
+#ifdef HAVE_MMAP
+ {
+#define M2048 (2048*8/64)
+ void *ptr[M2048];
+ int i;
+ for (i=0;i+ {
+ ptr[i] = malloc (64*1024);
+ }
+ for (i=M2048;i;i--)
+ {
+ free (ptr[i-1]);
+ }
+ }
+#endif
+}
#endif /* HAVE_SBRK */

void
@@ -107,9 +131,7 @@ xmalloc_set_program_name (const char *s)
{
name = s;
#ifdef HAVE_SBRK
- /* Win32 ports other than cygwin32 don't have brk() */
- if (first_break == NULL)
- first_break = (char *) sbrk (0);
+ check_first_break();
#endif /* HAVE_SBRK */
}

@@ -142,6 +164,10 @@ xmalloc (size_t size)
{
PTR newmem;

+#ifdef HAVE_SBRK
+ check_first_break();
+#endif /* HAVE_SBRK */
+
if (size == 0)
size = 1;
newmem = malloc (size);
@@ -156,6 +182,10 @@ xcalloc (size_t nelem, size_t elsize)
{
PTR newmem;

+#ifdef HAVE_SBRK
+ check_first_break();
+#endif /* HAVE_SBRK */
+
if (nelem == 0 || elsize == 0)
nelem = elsize = 1;

@@ -171,6 +201,10 @@ xrealloc (PTR oldmem, size_t size)
{
PTR newmem;

+#ifdef HAVE_SBRK
+ check_first_break();
+#endif /* HAVE_SBRK */
+
if (size == 0)
size = 1;
if (!oldmem)

拍手[0回]

PR

コメント

お名前
タイトル
文字色
メールアドレス
URL
コメント
パスワード Vodafone絵文字 i-mode絵文字 Ezweb絵文字

カレンダー

03 2024/04 05
S M T W T F S
1 2 3 4 5 6
7 8 9 10 11 12 13
14 15 16 17 18 19 20
21 22 23 24 25 26 27
28 29 30

フリーエリア

最新CM

最新記事

(07/27)
(03/27)
(03/26)
(03/23)
(03/22)
(03/19)
(03/18)
(03/18)
(03/15)
(03/14)
(03/13)
(03/12)
(03/11)
(03/11)
(03/08)
(03/08)
(03/06)
(03/05)
(03/02)
(03/01)
(02/28)
(02/27)
(02/24)
(02/23)
(02/22)

プロフィール

HN:
kenrou
性別:
非公開

バーコード

ブログ内検索

最古記事

(12/15)
(12/16)
(12/17)
(12/18)
(12/19)
(12/20)
(12/21)
(12/22)
(12/23)
(12/24)
(12/25)
(12/26)
(12/27)
(12/28)
(12/29)
(12/30)
(12/31)
(01/01)
(01/02)
(01/21)
(01/22)
(01/23)
(01/24)
(01/24)
(01/28)

P R

忍者アナライズ

コガネモチ

忍者カウンター

カレンダー

03 2024/04 05
S M T W T F S
1 2 3 4 5 6
7 8 9 10 11 12 13
14 15 16 17 18 19 20
21 22 23 24 25 26 27
28 29 30