Use memory area as stack space?

On Linux, can I start a process (for example, using execve ) and force it to use a specific memory area as the stack space?

Background:

I have a C ++ program and a quick allocator that gives me "quick memory". I can use it for objects that use a bunch, and create them in quick memory. Good. But I also have many variables living on the stack. How can I make them use fast memory?

Idea: Introduce a “software shell” that allocates fast memory and then launches the actual main program, passing a pointer to the main memory, and the program uses it as a stack. Is it possible?

[Update]

Setting up pthread works.

+7
source share
1 answer

With pthreads, you can use an additional thread for your program logic and set its stack address using 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. 

What I don't understand is how you expect to get any performance improvements from doing something like this (I assume that the goal of your “fast” memory is to increase performance).

+9
source

All Articles