2012-05-18 36 views
7

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

背景:

私はC++プログラムと私に「高速メモリ」を与える速いアロケータを持っています。ヒープを使用して高速メモリに作成するオブジェクトに使用できます。ファイン。しかし、私はまた、スタック上に多くの変数があります。どのようにして高速メモリを使用させることができますか?

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

[更新]

pthreadの設定がうまくいくようです。 pthreadsので

+3

私はあなたの* fast *アロケータがスタック割り当てよりも速くなるとは思っていません。一般に、スタック割り当ては関数ごとに2つの命令を要します。それとも、メモリがシステムの他の場所のメモリより速いことを意味しますか? –

+1

@DavidRodríguez-dribeas後者!そのメモリは、アロケータではなく速いです – ritter

+1

2つの異なるタイプのRAMがある場合、どのプラットフォームを使用していますか? –

答えて

9

、あなたのプログラムロジックのための二次スレッドを使用して、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. 

私は従っていない何があなたがいずれかを取得するために期待している方法ですこのようなことからパフォーマンスが改善されました(私はあなたの「高速」メモリの目的がより良いパフォーマンスであると想定しています)。

+2

恐ろしい!それは私の場合に動作するかどうかは分かりませんが、試してみましょう。あなたの質問:高速アロケータは 'cudaHostAlloc'はGPUへの高速メモリ転送に使われるページロックされたメモリを返します。したがって、これが動作すれば、スタック変数のコピーを高速化できます。 – ritter

+1

@フランク:面白い。それがどうなるか教えてください。 – NPE

関連する問題