小编sre*_*rna的帖子

javascript递归堆栈溢出

有没有人会解释为什么下面的结果有所不同?

// test one
function computeMaxCallStackSize() {
    try {
        return computeMaxCallStackSize() + 1;
    } catch (e) {
        return 1;
    }
}

console.log(computeMaxCallStackSize()); 
Run Code Online (Sandbox Code Playgroud)

结果是17958

// test two
    function computeMaxCallStackSize() {
        try {
            return 1 + computeMaxCallStackSize();
        } catch (e) {
            return 1;
        }
    }

    console.log(computeMaxCallStackSize());
Run Code Online (Sandbox Code Playgroud)

结果是15714

当函数'computeMaxCallStackSize'的位置不同时,结果也不同.什么原因?非常感谢!

运行环境: node.js v6.9.1 OS:Win7

javascript stack-overflow recursion node.js

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

使用 xlsx 模块读取工作表的前 n 行

我正在尝试使用 xlsx 模块从 Excel 工作表中读取前五行数据。最初,我尝试使用 sheet_to_json 方法将整个工作表数据转换为数组数组。

let sheetData = xlsx.utils.sheet_to_json(workbook.Sheets[sheetsList[i]], {
  header: 1,
  defval: '',
  blankrows: true
});
Run Code Online (Sandbox Code Playgroud)

但是当文件大小很大(工作表中存在> 10K 条记录)时会出现问题(内存不足)。

其次,我尝试使用以下链接:https : //github.com/SheetJS/js-xlsx/issues/214#issuecomment-96843418 但我收到以下错误:

    f:\xxx\node_modules\xlsx\xlsx.js:2774
function decode_range(range) { var x =range.split(":").map(decode_cell); return {s:x[0],e:x[x.length-1]}; }
                                            ^

TypeError: Cannot read property 'split' of undefined
Run Code Online (Sandbox Code Playgroud)

我该如何解决?或者它们是否有任何其他可用的方法或模块,以便我可以从 csv、xlsx、xls 中获取数据?

谢谢!

javascript xlsx node.js

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

修改windows中socket缓冲区大小的默认值

在socket编程中,当RAM大小大于19MB时,SO_SNDBUF和SO_RCVBUF将默认值为8192字节。

现在,我想更改套接字的套接字缓冲区大小。我知道一种方法是通过setsockopt。但是,我想对系统默认值应用更改,并且能够对我在系统中创建的所有套接字使用套接字缓冲区的修改值。请告诉我在windows平台上哪里可以进行配置更改?

c sockets windows

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

释放需要返回的动态分配的int,但不能在main中释放

正如我的长标题所说:我试图在c中返回一个动态分配的指针,我知道,我必须释放它,但我不知道如何对待自己,我的搜索显示它只能被释放main,但我不能让用户释放int.

我的代码现在看起来像这样,

int *toInt(BigInt *p)
{
    int *integer = NULL;

    integer = calloc(1, sizeof(int));

    // do some stuff here to make integer become an int from a passed
    // struct array of integers

    return integer;
}
Run Code Online (Sandbox Code Playgroud)

我试过制作一个临时变量并看到整数然后释放整数并返回临时值,但这没有用.必须有一种方法可以做到这一点,而不是在主?

c free memory-leaks

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

文件I/O代码中的指针声明

我无法理解如何声明指针的代码.

#include <stdio.h>

void openfile(char *, FILE **);
int main()
{
     FILE *fp;
     openfile("Myfile.txt",fp);

     if (fp == NULL)
        printf("Unable to open file..\n");

     fclose(fp);
     return 0;

}

void openfile(char *fn, FILE **f)
{
    *f = fopen(fn,"r");
}
Run Code Online (Sandbox Code Playgroud)

当我跑到上面的程序时,我得到2个警告......

file.c:9:3: warning: passing argument 2 of ‘openfile’ from incompatible pointer type [enabled by default]
     openfile("Myfile.txt",fp);
                           ^
file.c:3:6: note: expected ‘struct FILE **’ but argument is of type ‘struct FILE *’
void openfile(char *, FILE **);    
                   ^
Run Code Online (Sandbox Code Playgroud)

这些警告意味着什么?请问您能解释一下,如何在上面的代码中使用指针?

c pointers

-1
推荐指数
1
解决办法
66
查看次数