c语言中线程的内存分配
如何减少C中线程使用的内存?虽然一个线程需要8到10 MB的内存,但是有没有办法减少这个内存?是的,您可以设置线程堆栈的大小c语言中线程的内存分配,c,linux,C,Linux,如何减少C中线程使用的内存?虽然一个线程需要8到10 MB的内存,但是有没有办法减少这个内存?是的,您可以设置线程堆栈的大小 pthread_attr_t attribute; pthread_t thread; pthread_attr_init(&attribute); pthread_attr_setstacksize(&attribute,size); // size may be defined by u as 1024,2048,etc pthread_create(
pthread_attr_t attribute;
pthread_t thread;
pthread_attr_init(&attribute);
pthread_attr_setstacksize(&attribute,size); // size may be defined by u as 1024,2048,etc
pthread_create(&thread,&attribute,fun,0);
void *fun(void *arg)
{
....
}
如前所述,您可以在应用程序中使用pthread属性 但您也可以使用ulimit命令对当前shell中启动的任何应用程序设置限制:
:以千磅为单位显示当前限制ulimit-s
:将堆栈限制为1个MiBulimit-s1024