7

Linux では、プロセスを (たとえば でexecve) 開始し、特定のメモリ領域をスタック スペースとして使用させることはできますか?

バックグラウンド:

C++ プログラムと、「高速メモリ」を提供する高速アロケータがあります。ヒープを利用して高速メモリに作成するオブジェクトに使用できます。罰金。しかし、スタック上には多くの変数が存在しています。高速メモリも使用するにはどうすればよいですか?

アイデア: 高速メモリを割り当ててから実際のメイン プログラムを起動し、高速メモリへのポインタを渡す「プログラム ラッパー」を実装すると、プログラムはそれをスタックとして使用します。それは可能ですか?

[アップデート]

pthread セットアップは機能しているようです。

4

1 に答える 1

9

pthreadを使用すると、プログラムロジックにセカンダリスレッドを使用し、次を使用しスタックアドレスを設定できpthread_attr_setstack()ます。

NAME
       pthread_attr_setstack,  pthread_attr_getstack  -  set/get stack
       attributes in thread attributes object

SYNOPSIS
       #include <pthread.h>

       int pthread_attr_setstack(pthread_attr_t *attr,
                                 void *stackaddr, size_t stacksize);

DESCRIPTION
       The pthread_attr_setstack() function sets the stack address and
       stack  size attributes of the thread attributes object referred
       to by attr to the values specified in stackaddr and  stacksize,
       respectively.   These  attributes specify the location and size
       of the stack that should be used by a thread  that  is  created
       using the thread attributes object attr.

       stackaddr should point to the lowest addressable byte of a buf‐
       fer of stacksize bytes that was allocated by the  caller.   The
       pages  of  the  allocated  buffer  should  be both readable and
       writable.

私が従わないのは、このようなことを行うことでパフォーマンスの向上がどのように期待されるかです(「高速」メモリの目的はパフォーマンスの向上であると思います)。

于 2012-05-18T10:54:15.080 に答える