在Linux中,可以啓動一個進程(例如使用execve
)並使其將特定內存區域用作堆棧空間?使用內存區域作爲堆棧空間?
背景:
我有一個C++程序和快速的分配,讓我「快速記憶」。我可以將它用於使用堆的對象並在快速內存中創建它們。精細。但我也有很多可變的生活在堆棧中。我怎樣才能讓他們使用快速記憶?
想法:實現一個「程序包裝器」,它分配快速內存,然後啓動實際的主程序,將指針傳遞給快速內存,程序將其用作堆棧。那可能嗎?
[更新]
pthread安裝似乎工作。
在Linux中,可以啓動一個進程(例如使用execve
)並使其將特定內存區域用作堆棧空間?使用內存區域作爲堆棧空間?
背景:
我有一個C++程序和快速的分配,讓我「快速記憶」。我可以將它用於使用堆的對象並在快速內存中創建它們。精細。但我也有很多可變的生活在堆棧中。我怎樣才能讓他們使用快速記憶?
想法:實現一個「程序包裝器」,它分配快速內存,然後啓動實際的主程序,將指針傳遞給快速內存,程序將其用作堆棧。那可能嗎?
[更新]
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.
我不遵循的是你如何期待得到任何通過做這樣的事情來提升性能(我假設你的「快速」內存的目的是更好的性能)。
我真的不認爲你的* fast *分配器可以比堆棧分配更快。一般來說,堆棧分配每個函數需要幾條指令。或者你的意思是說,內存比系統中其他任何地方的內存更快*。 –
@DavidRodríguez-dribeas後者!它的內存很快,而不是分配器 – ritter
你使用哪種平臺,哪裏有兩種不同類型的RAM? –