我正在创建一个线程。但是,当我尝试在线程正在调用的函数中分配一些内存时,我遇到了Import-Module ActiveDirectory
# assuming the CSV uses commas as delimiter character. Otherwise, specify -Delimiter parameter
$list = Import-csv "\\ca23fs1\IT\Scripts\Active Directory\New-Hire\Account Setup\Users-Groups.csv"
foreach ($item in $list) {
# if you are not sure the CSV actually contains valid data to work with, check it here first:
if ([string]::IsNullOrWhiteSpace($item.UserName) -or [string]::IsNullOrWhiteSpace($item.Group)) {
Write-Warning "Empty entry found in the CSV file"
}
else {
Add-ADPrincipalGroupMembership -Identity $item.UserName -MemberOf $item.Group -Whatif
# The DriveLetter must be a single, uppercase letter and the colon is required.
Set-ADUser -Identity $item.UserName -HomeDirectory "Path" -HomeDrive 'H:' -WhatIf
}
}
异常。现在,从htop可以看到,我仍然有可用的内存(在大约100 Gb的总内存中)。此外,当我在主线程中调用相同的函数时,代码也可以工作。
这是我用来生成单线程的代码:
std::bad_array_new_length
我在这里有两个问题: 线程是否有其自己的内存限制(如在堆栈空间中)。如果是,如何使它把整个内存视为自己的内存?
答案 0 :(得分:1)
堆在所有线程之间共享(尽管TCMalloc之类的分配器利用堆的线程特定子集来进行短期分配以提高效率)。但是,bad_array_new_length
与内存耗尽无关:与不可能太大或否定的分配请求有关。