小编enk*_*nko的帖子

为什么在堆上迭代大型数组比在堆栈上迭代相同大小的数组更快?

我正在分配2个相同大小的数组,一个在堆栈上,一个在堆上,然后用简单的赋值迭代它们.

编译可执行文件以为主线程堆栈分配40mb.

此代码仅在vc ++中使用/ STACK:41943040链接器标记进行了测试.

#include "stdafx.h"
#include <string>
#include <iostream>
#include <malloc.h>
#include <windows.h>
#include <ctime>

using namespace std;

size_t stackavail()
{
    static unsigned StackPtr;   // top of stack ptr
    __asm mov [StackPtr],esp    // mov pointer to top of stack
    static MEMORY_BASIC_INFORMATION mbi;            // page range
    VirtualQuery((PVOID)StackPtr,&mbi,sizeof(mbi)); // get range
    return StackPtr-(unsigned)mbi.AllocationBase;   // subtract from top (stack grows downward on win)
}

int _tmain(int argc, _TCHAR* argv[])
{
    string input;

    cout << "Allocating 22mb on stack." << endl;
    unsigned …
Run Code Online (Sandbox Code Playgroud)

c++ visual-c++

5
推荐指数
2
解决办法
1343
查看次数

如何使用 vc++ 找出当前线程的堆栈上剩余多少空间?

我正在使用 VC++ 2012。我想知道当前线程中有多少堆栈内存可用。

快速搜索指向使用 malloc.h 和 stackavail() 函数,但它在 Visual C++ 2012 中不存在。我如何以另一种方式实现这一点?

有问题的例子是这样的:

#include "stdafx.h"
#include <iostream>
#include <malloc.h>

using namespace std;

int _tmain()
{
    cout << "Available stack: " << stackavail() << std::endl;
}
Run Code Online (Sandbox Code Playgroud)

c++ visual-c++

4
推荐指数
1
解决办法
2277
查看次数

如何在mac os x上安装旧版本的TypeScript?

我在Mac上使用WebStorm进行开发,最新的稳定版本仅支持0.8.x版本的TypeScript,而npm安装0.9.x,与IDE产生各种冲突.

目前npm将安装0.9.x版本:

npm install -g typescript
Run Code Online (Sandbox Code Playgroud)

如何强制它安装旧版本的TypeScript编译器?

compiler-construction macos npm typescript

4
推荐指数
1
解决办法
3608
查看次数

F#中int类型的NaN等效项是什么?

在F#中,我可以这样解析一个浮点数:

let tryParseFloat s =
    let ok,f = System.Double.TryParse s
    if ok then f else nan
Run Code Online (Sandbox Code Playgroud)

然后

let parsed = tryParse "123.123"
match parsed with
| nan -> ignore parsed
| _ -> dostuff parsed
Run Code Online (Sandbox Code Playgroud)

如何使用int实现类似的功能?

.net int f# tryparse

2
推荐指数
1
解决办法
1028
查看次数

标签 统计

c++ ×2

visual-c++ ×2

.net ×1

compiler-construction ×1

f# ×1

int ×1

macos ×1

npm ×1

tryparse ×1

typescript ×1