我的算法在几千数量级别都运行得好好的,到了上万级别的时候,发现运行出错。

malloc: *** mach_vm_map(size=18446744072119418880) failed (error code=3)

*** error: can't allocate region

*** set a breakpoint in malloc_error_break to debug

 

打印出来,元素个数,申请的内存,  虽然申请了这么多内存,但是实际上并没有占用了系统这么多内存。原来是类型int溢出,导致申请内存失败。所以,并不是申请的内存太大导致出错。

size is 26004
alloc 2579 MB
max profit 0