线程有不同的堆吗? [英] Do threads have a distinct heap?

查看:14
本文介绍了线程有不同的堆吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

据我所知,当操作系统创建线程时,每个线程都会获得一个不同的堆栈.我想知道每个线程是否也有一个与自己不同的堆?

As far as I know each thread gets a distinct stack when the thread is created by the operating system. I wonder if each thread has a heap distinct to itself also?

推荐答案

没有.所有线程共享一个公共堆.

No. All threads share a common heap.

每个线程都有一个私有堆栈,它可以快速添加和删除项目.这使得基于堆栈的内存快速,但是如果你使用太多的堆栈内存,就像在无限递归中发生的那样,你会得到堆栈溢出.

Each thread has a private stack, which it can quickly add and remove items from. This makes stack based memory fast, but if you use too much stack memory, as occurs in infinite recursion, you will get a stack overflow.

由于所有线程共享同一个堆,对分配器/释放器的访问必须同步.有多种方法和库可以避免 分配器争用.

Since all threads share the same heap, access to the allocator/deallocator must be synchronized. There are various methods and libraries for avoiding allocator contention.

某些语言允许您创建私有内存池或单独的堆,您可以将它们分配给单个线程.

Some languages allow you to create private pools of memory, or individual heaps, which you can assign to a single thread.

这篇关于线程有不同的堆吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆