使用内存区域作为堆栈空间?

rit*_*ter 7 c c++ linux memory stack

在Linux中是否可以启动一个进程(例如with execve)并使其使用特定的内存区域作为堆栈空间?

背景:

我有一个C++程序和一个快速分配器,给我"快速记忆".我可以将它用于使用堆的对象并在快速内存中创建它们.精细.但我也有很多变量生活在堆栈上.我怎样才能让他们使用快速记忆?

想法:实现一个"程序包装器",它分配快速内存,然后启动实际的主程序,将指针传递给快速内存,程序将其用作堆栈.那可能吗?

[更新]

pthread设置似乎工作.

NPE*_*NPE 9

使用pthreads,您可以为程序逻辑使用辅助线程,并使用以下命令设置堆栈地址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.
Run Code Online (Sandbox Code Playgroud)

我不遵循的是你如何期望通过做这样的事情来获得任何性能改进(我假设你的"快速"内存的目的是更好的性能).

  • 真棒!不确定它是否适用于我的情况,会试一试.您的问题:快速分配器是`cudaHostAlloc`返回页锁定内存,用于加速内存传输到GPU.因此,如果这有效,我可以加速堆栈变量的复制! (2认同)