小编Lau*_*arn的帖子

我什么时候应该担心对齐?

我最近学到了一些关于对齐的知识,但我不确定在哪种情况下它会成为一个问题.我怀疑有两种情况:

第一个是使用数组时:

struct Foo {
    char data[3]; // size is 3, my arch is 64-bit (8 bytes)
};

Foo array[4]; // total memory is 3 * 4 = 12 bytes. 
              // will this be padded to 16?

void testArray() {
    Foo foo1 = array[0];
    Foo foo2 = array[1]; // is foo2 pointing to a non-aligned location?
                           // should one expect issues here?
}
Run Code Online (Sandbox Code Playgroud)

第二种情况是使用内存池时:

struct Pool {
    Pool(std::size_t size = 256) : data(size), used(0), freed(0) { }

    template<class T>
    T …
Run Code Online (Sandbox Code Playgroud)

c++

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

ICloneable接口

这涉及到《Watson et al: Beginning Visual C# Chapter 10:exercise 4》:在 People 类上实现 ICloneable 接口以提供深度复制功能

class People : DictionaryBase: ICloneable

    public void DictAdd(Person newPerson)
    {
        Dictionary.Add(newPerson.Name, newPerson);

    public object Clone()
    {

        People newPeople = new People();


        foreach (Person myPerson in Dictionary.Values)
        {
            Person ClonePerson = (Person)myPerson.Clone();
            newPeople.DictAdd(ClonePerson);
        }

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

在 Person 类中,我们有:

        public object Clone()
    {
        Person newPerson = new Person();
        newPerson = (Person)newPerson.MemberwiseClone();
        newPerson.Age = age;
        newPerson.Name = name;
        return newPerson;

    }
Run Code Online (Sandbox Code Playgroud)

要在 Program.cs 中测试它:

People clonedPeople = (People)PeopleCollection.Clone(); …
Run Code Online (Sandbox Code Playgroud)

c# recursion icloneable

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

批处理文件中的括号

这段代码的括号出现了奇怪的事情:

Setlocal EnableDelayedExpansion
MyFOLDER=
FOR %%B IN (c,d,e,f,g) DO (@%%B: 2>nul && set z=%%B <nul if exist %z%\
(if %MYFOLDER%==[] (echo %z%
)
)
)
Run Code Online (Sandbox Code Playgroud)

以上编译,但这不是:

Setlocal EnableDelayedExpansion
MyFOLDER=
FOR %%B IN (c,d,e,f,g) DO (@%%B: 2>nul && set z=%%B <nul if exist %z%\
(if %MYFOLDER%==[] (
echo %z%
)
)
)
Run Code Online (Sandbox Code Playgroud)

也不是这个

Setlocal EnableDelayedExpansion
MyFOLDER=
FOR %%B IN (c,d,e,f,g) DO (@%%B: 2>nul && set z=%%B <nul if exist %z%\
(if %MYFOLDER%==[]
(
echo %z%
)
)
)
Run Code Online (Sandbox Code Playgroud)

也不是"echo%z%"低于(如果是MYFOLDER)行的任何其他组合."FOR"行中有什么可疑的吗?

batch-file parentheses

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

标签 统计

batch-file ×1

c# ×1

c++ ×1

icloneable ×1

parentheses ×1

recursion ×1