小编Ebo*_*air的帖子

C++原子数组是否也需要是原子的?

我有一些代码如下:

KMessageQueue::KMessageQueue()
{    
    messages = new atomic<KBuffer*>[MAX_MESSAGES];
    for (int i = 0; i < MAX_MESSAGES; i++)
        messages[i].store(nullptr);
}
Run Code Online (Sandbox Code Playgroud)

其中messages是KMessageQueue的成员,定义如下:

std::atomic<KBuffer*>* messages;
Run Code Online (Sandbox Code Playgroud)

所以messages数组中的每个元素都是原子的,我从另一个线程读取它们.但是数组指针本身也需要是原子的吗?在构造函数完成后,另一个线程是否可以尝试访问消息,只是发现消息尚未分配值?

c++ arrays multithreading atomic

5
推荐指数
1
解决办法
784
查看次数

.NET为什么无法检测到文件路径较长的目录?

如果这些文件的完整路径超过260个字符,则无法枚举目录中包含的文件。以下代码显示了该问题:

void TestLongPath(DirectoryInfo testDirectory)
{
    if (testDirectory.Exists)
    {
        try
        {
            testDirectory.GetFiles("SomeFileNamePattern*");
        }
        catch (System.IO.DirectoryNotFoundException)
        {
            Console.WriteLine("Long path test failed for " + testDirectory.FullName);
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

我的app.manifest文件包含:

<application xmlns="urn:schemas-microsoft-com:asm.v3">
    <windowsSettings>
        <longPathAware xmlns="http://schemas.microsoft.com/SMI/2016/WindowsSettings">true</longPathAware>
    </windowsSettings>
</application>
Run Code Online (Sandbox Code Playgroud)

但是所有要做的就是将错误从PathTooLongException更改为DirectoryNotFoundException。

这是我的App.config:

<?xml version="1.0" encoding="utf-8"?><configuration>
<startup> 
    <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.7.2"/>
</startup>
<runtime>
    <AppContextSwitchOverrides value="Switch.System.IO.UseLegacyPathHandling=false;Switch.System.IO.BlockLongPaths=false" />
</runtime></configuration>
Run Code Online (Sandbox Code Playgroud)

我在Windows 10 Pro上,使用Visual Studio 2019 16.1.1。我的目标是.NET 4.7.2。

如何枚举这些超长目录中的文件?它们位于我无法控制的共享网络驱动器上,因此重命名目录对我来说不是一种选择。

.net c# long-filenames pathtoolongexception

5
推荐指数
1
解决办法
101
查看次数