我写了一个基于C的应用程序似乎运行正常,除了非常大的数据集作为输入.
对于大输入,我在二进制函数的结束步骤中得到分段错误.
我运行二进制文件(带有测试输入)valgrind:
valgrind --tool=memcheck --leak-check=yes /foo/bar/baz inputDataset > outputAnalysis
Run Code Online (Sandbox Code Playgroud)
这项工作通常需要几个小时,但valgrind需要七天时间.
不幸的是,在这一点上,我不知道如何阅读我从这次运行中获得的结果.
我收到了很多这些警告:
...
==4074== Conditional jump or move depends on uninitialised value(s)
==4074== at 0x435900: ??? (in /foo/bar/baz)
==4074== by 0x439CC5: ??? (in /foo/bar/baz)
==4074== by 0x400BF2: ??? (in /foo/bar/baz)
==4074== by 0x402086: ??? (in /foo/bar/baz)
==4074== by 0x402A0F: ??? (in /foo/bar/baz)
==4074== by 0x41684F: ??? (in /foo/bar/baz)
==4074== by 0x4001B8: ??? (in /foo/bar/baz)
==4074== by 0x7FEFFFF57: ???
==4074== Uninitialised value was created
==4074== at …Run Code Online (Sandbox Code Playgroud) 可能重复:
无效的读/写有时会产生分段错误,有时则不会
我有以下代码:
#include <stdlib.h>
#include <stdio.h>
int main() {
int *ptr = NULL;
ptr = malloc(sizeof(char));
if (ptr) {
*ptr = 10;
printf("sizeof(int): %zu\nsizeof(char): %zu\n", sizeof(int), sizeof(char));
printf("deref of ptr: %d\n", *ptr);
free(ptr);
return EXIT_SUCCESS;
}
else
return EXIT_FAILURE;
}
Run Code Online (Sandbox Code Playgroud)
当我编译并运行它时,我得到以下输出:
$ gcc test.c
$ ./a.out
sizeof(int): 4
sizeof(char): 1
deref of ptr: 10
Run Code Online (Sandbox Code Playgroud)
该值sizeof(char)小于sizeof(int).我的malloc电话只留出足够的空间char.然而,我的程序能够分配一个整数值而ptr不会崩溃.为什么这样做?
在C或C++中,以下内容可用于返回文件大小:
const unsigned long long at_beg = (unsigned long long) ftell(filePtr);
fseek(filePtr, 0, SEEK_END);
const unsigned long long at_end = (unsigned long long) ftell(filePtr);
const unsigned long long length_in_bytes = at_end - at_beg;
fprintf(stdout, "file size: %llu\n", length_in_bytes);
Run Code Online (Sandbox Code Playgroud)
是否有基于填充或特定情况的其他信息,可以从此代码返回错误文件大小的开发环境,编译器或操作系统?在1999年左右,C或C++规范是否有变化,这会导致此代码在某些情况下不再起作用?
对于这个问题,请假设我通过使用标志进行编译来添加大文件支持-D_FILE_OFFSET_BITS=64 -D_LARGEFILE64_SOURCE=1.谢谢.
我有一个d3强制导向图,其中包含一组节点:
var node = vis.selectAll("g.node")
.data(json.nodes)
.enter().append("svg:g")
.attr("class", "node")
.attr("id", function(d) { return "node" + d.index; })
.attr("transform", function(d) { return "translate(" + d.x + "," + d.y + ")"; })
.call(force.drag);
Run Code Online (Sandbox Code Playgroud)
这很好.
我现在想要在显示div带有id 的细节时将这些节点转换(移动)到右边200个像素detail_container.
我尝试了以下操作,但是当我显示时节点没有任何反应detail_container(除了显示细节div):
$('#detail_container').fadeIn('slow', function() {
d3.selectAll("g.node").attr("transform", function(d) { return "translate(200, 0)"; });
});
Run Code Online (Sandbox Code Playgroud)
该d3.selectAll("g.node")语句包含节点数据,我可以通过查看控制台中的数据来确认:
console.log(d3.selectAll("g.node"));
Run Code Online (Sandbox Code Playgroud)
作为另一种方法,我将缩放/平移行为附加到我的图表:
var vis = d3.select("#position")
.append("svg:svg")
.attr("width", w)
.attr("height", h)
.attr("pointer-events", "all")
.append("svg:g")
.call(d3.behavior.zoom().on("zoom", redraw))
.append("svg:g");
Run Code Online (Sandbox Code Playgroud)
这很好用.但是,这与鼠标交互,而不是与我的程序中发生的事件交互,因此是否有一种编程方式来调用缩放/平移行为,以便我可以完成我想要的翻译?
我想知道安装的mac上似乎没有文本编辑器能够只保存文本而不需要任何格式化.您知道哪些纯文本编辑器允许编辑文本而不使用字体大小等任何格式?
我几天前开始使用objective-c/iphone编程,并且仍然遇到一些从其他语言转换的问题..我正在使用NSArrays和NSMutableArrays进行测试,而且我还没有发现它真烦人任何有效显示我的数组内容的方法(不创建循环并逐行显示).
是否有一些简单的方法,如PHP中的print_r或javascript中的console.log(w/Firefox && firebug)?
真的很感激任何帮助:)
在我的应用程序中,我使用的是自定义表.每个细胞都有一个uibutton和uiimage.当触摸按下按钮时,我想调用uiimagepickercontroller方法从iphone库中选择一张图片并将其显示在图像视图中.我已经写了但收到警告......'customCell'可能无法响应presentmodalviewcontroller动画...这里customCell是我的主类myApp的子类,也是自定义单元格的nib的名称.谁知道这个问题???? 谢谢...
编辑
- (IBAction)selectExistingPicture1 {
if ([UIImagePickerController isSourceTypeAvailable: UIImagePickerControllerSourceTypePhotoLibrary]) {
UIImagePickerController *picker = [[UIImagePickerController alloc] init];
picker.delegate = self;
picker.allowsImageEditing = YES;
picker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
[self presentModalViewController:picker animated:YES];
[picker release];
}
else {
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Error accessing photo library" message:@"Device does not support a photo library" delegate:nil cancelButtonTitle:@"Drat!" otherButtonTitles:nil];
[alert show];
[alert release];
}
}
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingImage:(UIImage *)image editingInfo:(NSDictionary *)editingInfo {
CGSize newSize = CGSizeMake(80, 80);
UIGraphicsBeginImageContext( newSize );
[image drawInRect:CGRectMake(0,0,newSize.width,newSize.height)];
UIImage* newImage = …Run Code Online (Sandbox Code Playgroud) 我有一个由一些bzip2档案组成的连接文件.我也知道该bzip2文件中各个块的大小.
我想bzip2从单个bzip2数据块解压缩流,并将输出写入标准输出.
首先,我使用fseek将文件光标移动到所需的存档字节,然后将文件的"size"-chunk读入BZ2_bzRead调用:
int headerSize = 1234;
int firstChunkSize = 123456;
FILE *fp = fopen("pathToConcatenatedFile", "r+b");
char *bzBuf = malloc(sizeof(char) * firstChunkSize);
int bzError, bzNBuf;
BZFILE *bzFp = BZ2_bzReadOpen(&bzError, *fp, 0, 0, NULL, 0);
# move cursor past header of known size, to the first bzip2 "chunk"
fseek(*fp, headerSize, SEEK_SET);
while (bzError != BZ_STREAM_END) {
# read the first chunk of known size, decompress it
bzNBuf = BZ2_bzRead(&bzError, bzFp, bzBuf, …Run Code Online (Sandbox Code Playgroud) 我使用的是 Firefox 3.6.10(OS X Intel),浏览器收集新的 cookie,而不是使旧的 cookie 过期(“删除”)。
这些 cookie 是通过 PerlCGI和CGI::Cookie模块创建和添加的。
我正在创建和添加一个 cookie,如下所示:
my $myNewCookie = new CGI::Cookie(-name => "$myCookieName",
-value => { 'key1' => $value1, 'key2' => $value2 },
-expires => '+8h',
-secure => 1
);
print redirect(-URL => "$hostURL$redirect",
-cookie => $myNewCookie);
Run Code Online (Sandbox Code Playgroud)
这是我试图让它们过期的方法:
sub clearCookie {
my $myOldCookie = cookie(-name => "$myCookieName",
-value => '',
-expires => '-1d',
-secure => 1);
print header(-cookie=>$myOldCookie);
# ...
}
Run Code Online (Sandbox Code Playgroud)
这是发生的事情:
假设我有一个upstream存储库,我已将其分叉到一个新的origin.
如果我想将来自上游 repo 的更改合并到我的分叉源中,我会在分叉中执行以下操作:
$ git merge upstream/master
Run Code Online (Sandbox Code Playgroud)
我将如何走向另一个方向,从原点到上游?假设我在 fork 中更改了一些我想推送给父级的东西——我该怎么做?
是否只是为父级设置新的远程/上游,将叉用作父级的问题upstream?
c ×4
iphone ×2
bzip2 ×1
c++ ×1
cgi ×1
compression ×1
cookies ×1
d3.js ×1
debugging ×1
events ×1
file-io ×1
force-layout ×1
fseek ×1
ftell ×1
gcc ×1
geometry ×1
git ×1
git-merge ×1
https ×1
javascript ×1
macos ×1
malloc ×1
memory ×1
objective-c ×1
perl ×1
porting ×1
text-editor ×1
uitableview ×1
valgrind ×1