我错误地做了相反的事情,现在我不能回到java环境.anyoune怎么知道?谢谢.
我正在尝试从套接字读取并使用printf打印到stdout(必须);
但是,每当我从理智的网站上读取特定文件(HTML)时,我都会收到分段错误.
请看一下这段代码并告诉我有什么不对.
int total_read = 0;
char* read_buff = malloc(BUF_SIZE);
char* response_data = NULL;
if (read_buff == NULL){
perror("malloc");
exit(1);
}
while((nbytes = read(fd, read_buff, BUF_SIZE)) > 0){
int former_total = total_read;
total_read += nbytes;
response_data = realloc(response_data, total_read);
memmove(response_data + former_total, read_buff, nbytes); //start writing at the end of spot before the increase.
}
if (nbytes < 0){
perror("read");
exit(1);
}
printf(response_data);
Run Code Online (Sandbox Code Playgroud)
谢谢.
我有一个填充的 Shape,和一个与Shape的边界框宽度和高度相同的BitmapData.
我需要从BitmapData中剪切Shape(基本上将BitmapData绘制到形状上......)[如此:http://imgur.com/uwE5F.png ]
我使用相当hackish方法:
public static function cutPoly(img:BitmapData, s:Shape, bounds:Bounds):BitmapData {
var temp:BitmapData = new BitmapData(bounds.width, bounds.height, true);
Main.inst.stageQuality("low"); //hack to kill anti-aliasing
temp.draw(s,new Matrix());
Main.inst.stageQuality("high"); // end hack
//0xFF00FF00 is the color of the shape
makeColTrans(temp,0xFF00FF00); //makes the color transparent :P
//return temp;
img.draw(temp);
//img.draw(temp);
temp.dispose();
makeColTrans(img, 0xFFFFFFFF);
return img;
}
Run Code Online (Sandbox Code Playgroud)
我想知道是否有更好的方法......一个不仅仅是一个黑客.
我在@GWW的帮助下想到了这段代码,但现在我不能free了char**。
这是我的代码(它只是读取输入文件并在屏幕上打印名称):
/* deallocate2D
corresponding function to dynamically deallocate 2-dimensional array using
* malloc.
* accepts a char** as the "array" to be allocated, and the number of rows.
* as with all dynamic memory allocation, failure to free malloc'ed memory
* will result in memory leaks
*/
void deallocate2D(char** array, int nrows) {
/* deallocate each row */
int i;
for (i = 0; i < nrows; i++) {
free(array[i]);
}
/* deallocate array of …Run Code Online (Sandbox Code Playgroud) 我希望能够获取一个声明文件,例如:
test_1 = assert $ 1 == 1
test_2 = assert $ 2 == 1
Run Code Online (Sandbox Code Playgroud)
并生成一个基本的运行函数
main = runTests [test_1, test2]
Run Code Online (Sandbox Code Playgroud)
目标是获得像Python一样的东西.
我可以用模板Haskell做到这一点吗?我找不到很多关于它的文档(Wiki中有很多断开的链接).
我很好奇是否以及如何使Controller成为两个不同对象的委托.
这是允许的还是像Java中的多重继承?
假设我想要一个响应的控制器:<UIAccelerometerDelegate>和<CLLocationManagerDelegate>
头文件看起来像这样吗?
@interface MainViewController : UIViewController <UIAccelerometerDelegate> AND <CLLocationManagerDelegate> {
Run Code Online (Sandbox Code Playgroud) 我说,我的表中有专栏updateStamp.我希望得到一种方法,在行更新时使用新的序列号更新该字段.
数据库有很多流量,主要是读取,但多个并发更新也可以批量发生.因此,解决方案应该导致最小的锁.
这个要求的原因是我需要有一个解决方案让客户端迭代表转发,如果一行更新 - 它应该再次出现在结果集上.
那么,查询就好了
SELECT *
FROM mytable
WHERE updateStamp > @lastReturnedUpdateStamp
ORDER BY updateStamp
Run Code Online (Sandbox Code Playgroud)
不幸的是,时间戳在这里不起作用,因为多个更新可能同时发生.
我正在尝试创建一组半复杂的视图动画(想想一个NSMatrix表单的动画版本,其中行在添加或删除其他行时滑动),并构建动画我正在制作一个小帮助类.
在那里,我必须跟踪不同的视图,他们的有序索引,以及与他们的动画相关的一些其他值.
为此,我正在使用一个NSArray实例来跟踪视图的排序(索引),并且我想使用NSDictionary带有视图作为键来跟踪值(值本身在嵌套字典中) ).即我希望能够做一些这样的事情,例如(伪代码):
NSMutableDictionary* viewValuesDict = [NSDictionary dictionary];
// Loop thru an ordered NSArray
for( (NSView*) view in viewsArray ) {
// Get some values we'll need later
NSDictionary* associatedValues = [view getSomeValues];
// ...and put them into viewValuesDict...
[viewValuesDict setObject:associatedValues forKey:view];
// and then things break because the NSView 'view'
// doesn't support copyWithZone.... darn
}
Run Code Online (Sandbox Code Playgroud)
问题是,我当然不能将NSView实例用作字典键,因为键是使用添加的copyWithZone,而NSView不是实现.
那么,为NSView实例获取唯一键的好方法是什么?我可以想象使用,[obj description]因为你得到的内存地址是一个完美的UID,但当然系统必须使用任何类型的NSView子类,可能完全返回其他东西,所以这是不好的. …
我有这行代码:
delete_btn = uicontrol(rr_ops, 'Style', 'pushbutton', 'String', 'Delete Graphic', 'Position', [13 135 98 20], ...
'Callback', 'delete_graphic');
Run Code Online (Sandbox Code Playgroud)
并且稍微提高了这个功能:
function delete_graphic
global rr_list
selected = get(rr_list, 'Value');
selected
return;
Run Code Online (Sandbox Code Playgroud)
为什么这段代码不起作用?我真的不明白......
我需要什么?我创建了一个按钮和一个列表框,单击按钮 - 从列表框中删除所选元素.
谢谢你的帮助.
PS总是收到此错误:
??? Undefined function or variable 'delete_graphic'.
??? Error while evaluating uicontrol Callback
Run Code Online (Sandbox Code Playgroud)
这是我的所有代码:http://paste.ubuntu.com/540094/(第185行)
看起来很容易使用任何支持此功能的HTTP头客户端向您的websocket客户端添加自定义HTTP标头,但我无法找到如何使用JSON API执行此操作.
任何人都知道如何实现它?
var ws = new WebSocket("ws://example.com/service");
Run Code Online (Sandbox Code Playgroud)
具体来说,我需要能够发送HTTP授权标头.
c ×3
objective-c ×2
actionscript ×1
bitmap ×1
bitmapdata ×1
c++ ×1
callback ×1
cocoa ×1
delegates ×1
eclipse ×1
flash ×1
function ×1
haskell ×1
header ×1
http ×1
iphone ×1
java ×1
javascript ×1
malloc ×1
matlab ×1
memory ×1
nsdictionary ×1
nsview ×1
printf ×1
sequence ×1
sql-server ×1
websocket ×1