小编Ver*_*rax的帖子

GCC --gc-sections和查找符号依赖项

我正在尝试减少我的elf可执行文件的大小.我正在编译-ffunction-sections -fdata-sections和链接-gc-sections,但似乎我认为未使用的一些符号不会被丢弃.

在GNU工具链中是否有一些命令可以运行以找出正在使用的符号以及在哪里?

  • 工具链:GNU arm-none-eabi
  • 平台:Cortex-M4
  • 语言:C++

这是我的典型构建标志:

汇编: arm-none-eabi-g++.exe -Wall -O3 -mthumb -std=c++11 -mcpu=cortex-m4 -mfpu=fpv4-sp-d16 -mfloat-abi=softfp -fsingle-precision-constant -ffunction-sections -fdata-sections

链接: arm-none-eabi-g++.exe -static -mthumb -mcpu=cortex-m4 -mfpu=fpv4-sp-d16 -mfloat-abi=softfp -Wl,-gc-sections -Wl,-T"LinkerScript.ld

谢谢您的帮助.

c++ embedded gcc thumb

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

何时使用除int之外的数据类型?

我有一个项目,其中我有许多具有许多属性的对象,其值始终小于60,100和255之类的小数字.

我知道在进行数学运算时byte,有必要投射结果.但除此之外,使用a byte或者short所有这些属性是否有任何不利之处?或者另一种看待它的方式,使用bytes或shorts而不是int

.net c# int byte short

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

使用NetworkStream.BeginRead和NetworkStream.EndRead实现超时

我编写了以下函数来使用NetworkStream异步读取函数(BeginReadEndRead)实现超时功能.它工作正常,直到我注释掉该行Trace.WriteLine("bytesRead: " + bytesRead);.为什么?

private int SynchronousRead(byte[] buffer, int count)
{
    int bytesRead = 0;
    bool success = false;
    IAsyncResult result = null;

    result = _stream.BeginRead(
        buffer, 0, count,
        delegate(IAsyncResult r)
        {
            bytesRead = _stream.EndRead(r);
        },
        null);

    success = result.AsyncWaitHandle.WaitOne(_ioTmeoutInMilliseconds, false);

    if (!success)
    {
        throw new TimeoutException("Could not read in the specfied timeout.");
    }

    //If I remove this line, bytesRead is always 0
    Trace.WriteLine("bytesRead: " + bytesRead);

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

万一你想知道,我必须这样做,因为我最终需要针对.Net Compact …

.net c# asynchronous networkstream

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

我需要一个适用于任何.Net数据类型的公共类/接口

我正在寻找一种方法来一致地处理所有.Net数据类型,所以我可以在下面创建任何类型实现IGetValue<out T>将转换为的模式IGetValue<object>.出于某种原因,如果T是a struct,它不起作用,我不明白为什么.有没有办法可以实现以下模式?

public interface IGetValue<out T>
{
    T Value
    {
        get;
    }
}

public class GetValue<T> : IGetValue<T>
{
    public GetValue(T value)
    {
        _value = value;
    }

    private T _value;
    public T Value
    {
        get { return _value; }
    }
}


class Program
{
    static void Main(string[] args)
    {
        IGetValue<string> GetString = new GetValue<string>("Hello");
        IGetValue<int> GetInt = new GetValue<int>(21);

        //This works!!!
        if (GetString is IGetValue<object>)
        {
            Console.WriteLine("GetValue<string> is an IGetValue<object>");
        }
        else
        {
            Console.WriteLine("GetValue<string> …
Run Code Online (Sandbox Code Playgroud)

.net c#

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

标签 统计

.net ×3

c# ×3

asynchronous ×1

byte ×1

c++ ×1

embedded ×1

gcc ×1

int ×1

networkstream ×1

short ×1

thumb ×1