问题列表 - 第33780页

使用fopen时使用valgrind检测到泄漏

gcc 4.4.4 c89 valgrind 3.5.0.

当我使用文件指针打开文件时,我检测到泄漏.

==17681==    in use at exit: 352 bytes in 1 blocks
==17681==    total heap usage: 1 allocs, 0 frees, 352 bytes allocated
==17681== 
==17681==    352 bytes in 1 blocks are still reachable in loss record 1 of 1
==17681==    at 0x4005BDC: malloc (vg_replace_malloc.c:195)
==17681==    by 0xAAD67E: __fopen_internal (iofopen.c:76)
==17681==    by 0xAAD74B: fopen@@GLIBC_2.1 (iofopen.c:107)
Run Code Online (Sandbox Code Playgroud)

它指向的代码行是这个fopen:

FILE *fp = NULL;
fp = fopen("input.txt", "r");
if(fp == NULL) {
    fprintf(stderr, "Failed to open file [ %s ]\n", strerror(errno)); …
Run Code Online (Sandbox Code Playgroud)

c valgrind

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

Ruby需要路径

我有一个Ruby代码,在几个文件中有不同的类.在一个文件中,我开始执行.这个文件require是我的其他文件.

  • 这是启动ruby代码的好方法吗?
  • 当我从符号链接运行代码时,例如DIR2/MyRubyCode是指向主文件的链接DIR1/MyRubyCode.rb,那么我的要求将失败.我通过在之前添加路径DIR1来解决问题,但我认为有更好的方法来实现它.你对此有什么建议吗?$LOAD_PATHrequire

ruby require

12
推荐指数
3
解决办法
3万
查看次数

什么是16位,32位和64位架构?

在微处理器和/或操作系统的情况下,16位,32位和64位架构意味着什么?

在微处理器的情况下,它是指General Purpose Registers的最大尺寸或s的大小Integer或数量Address-line或s的数量Data Bus line或者是什么?

说" DOS is a 16-bit OS"," Windows in a 32-bit OS"等是什么意思?

64-bit operating-system 32-bit 16-bit microprocessors

25
推荐指数
3
解决办法
2万
查看次数

如何在Java中的if语句中为变量赋值

我需要做这样的事情,

if (first_var > second_var)
  int difference = first_var - second_var;
if (first_var < second_var)
  int difference = second_var - first_var;
Run Code Online (Sandbox Code Playgroud)

当我尝试编译它时,会出现一个错误,指出变量"差异"可能尚未初始化.使变量"差异"全局也无济于事.

java

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

问题数据绑定到UserControl上的DependencyProperty

我有一个UserControl我已经添加了一个依赖属性:

public partial class WordControl : UserControl
{

    // Using a DependencyProperty as the backing store for WordProperty.  This enables animation, styling, binding, etc...
    public static readonly DependencyProperty WordProperty =
        DependencyProperty.Register("WordProperty", typeof(string), typeof(WordControl), new FrameworkPropertyMetadata("", OnWordChange));

    public string Word
    {
        get { return (string)GetValue(WordProperty); }
        set { SetValue(WordProperty, value); }
    }
Run Code Online (Sandbox Code Playgroud)

当我在XAML中手动设置Word属性时,哪个工作正常:

<WordGame:WordControl Word="Test"></WordGame:WordControl>
Run Code Online (Sandbox Code Playgroud)

但是,我想将此UserControl用作ListBox的Item Template的一部分,并使用Data Binding来设置单词:

    <ListBox Name="WordList" IsEnabled="False" IsHitTestVisible="False">
        <ListBox.ItemTemplate>
            <DataTemplate>
                <Grid>
                    <WordGame:WordControl Word="{Binding}"></WordGame:WordControl>
                </Grid>
            </DataTemplate>
        </ListBox.ItemTemplate>
    </ListBox>
Run Code Online (Sandbox Code Playgroud)

运行时会出现以下错误:

无法在"WordControl"类型的"Word"属性上设置"绑定".'绑定'只能在DependencyObject的DependencyProperty上设置.

由于UserControl继承自DependencyObject,我只能假设问题在于DependencyProperty,但没有任何数量的Google搜索找到了答案.

有任何想法吗?

wpf binding

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

是否可以从远程Oracle数据库中读取CLOB?

关于SO问题的这个答案

...您可以从远程数据库读取LONG,但无法读取CLOB

我没有在互联网上找到任何关于此的信息,这是真的吗?任何文档或引用都会有所帮助.

database oracle

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

歧视的工会和继承

我正在为我的F#项目创建一个场景图:

root
->player_bob
-->torch
->enemy_1
-->extravagant_hat
-->enemies_cat_jess 
--->fleas
--->fur_ball
->loot
Run Code Online (Sandbox Code Playgroud)

等等,等等.

每个项目都需要保存一组游戏对象来代表它的孩子.

例如,enemy1的列表包含猫和帽子,猫列表包含跳蚤和毛球

所以我计划让它们全部继承自一个包含描述对象子集合的集合的类.

现在回答我的问题: 我应该将子对象向下转换为GameObject,并将它们存储在"GameObject"基类的列表中,或者创建一个有区别的联合,例如

type SceneObject = 
        |Character of Character //e.g player, enemy, cat
        |Item of Item //e.g hat, torch, furball
Run Code Online (Sandbox Code Playgroud)

并将对象存储为"SceneObjects"列表,以避免任何问题/开销,以及向上转换它们等.同时允许我描述在碰撞检测中不渲染和/或不使用对象的特殊情况,例如:声音发射器,陷阱触发器等

歧视的联合+继承组合是我最初的想法; 尽管如此,由于我是FP的新手,我认为向专业人士询问最佳,实用,接近这一点的方式是明智的.

谢谢,

JD

inheritance f# discriminated-union

4
推荐指数
2
解决办法
1637
查看次数

在c#中将显示发送到睡眠模式

这是一个标准的Windows功能,显示器在配置的时间后进入睡眠模式.是否有可能立即从Windows 7中的ac#.net应用程序将显示器发送到睡眠模式?我已经尝试过一件我发现的东西,但它对我不起作用.

[DllImport("user32.dll")]
static extern IntPtr SendMessage(IntPtr hWnd, UInt32 Msg, IntPtr wParam, IntPtr lParam);

[DllImport("user32.dll", CharSet = CharSet.Auto, ExactSpelling = true)]
public static extern IntPtr GetDesktopWindow();

private const int SC_MONITORPOWER = 0xF170;
private const UInt32 WM_SYSCOMMAND = 0x0112;
private const int MONITOR_ON = -1;
private const int MONITOR_OFF = 2;
private const int MONITOR_STANBY = 1;

public static void DisplayToSleep()
{
    var hWnd = GetDesktopWindow();
    var ret = SendMessage(hWnd , Constants.WM_SYSCOMMAND, (IntPtr)Constants.SC_MONITORPOWER, (IntPtr)Constants.MONITOR_OFF);
}
Run Code Online (Sandbox Code Playgroud)

hWnd似乎有一个有效值,但ret始终为0.

thx,kopi_b

c#

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

Go的游戏算法?

Go游戏的算法技术水平是什么?
最好阅读哪些文章(描述算法)?

有一个专门用于Go 的StackExachge网站,但没有足够的人承诺在那里提出问题.

algorithm search artificial-intelligence baduk

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

为什么fread总是返回0?

我用这段代码来读取文件.但是fread功能总是返回0.我的错误是什么?

FILE *file = fopen(pathToSourceFile, "rb");
if(file!=NULL) 
{
    char aByte[50000];
    int ret = fread(aByte, sizeof(aByte), 1, file);
    if(ret != 0)
    {
        not jump into there;
        fseek(file, 0, SEEK_SET);
        fwrite(aByte, ret, 1, file);
    }
} 
fclose(file); 
Run Code Online (Sandbox Code Playgroud)

c file-io

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