小编Jon*_*ric的帖子

glClear()如何提高性能?

Apple关于解决闪烁问题的技术问答(QA1650)包括以下段落.(强调我的.)

您必须为屏幕上的每个像素提供一种颜色.在绘图代码的开头,最好使用glClear()来初始化颜色缓冲区.在帧开始时全屏清除每个颜色,深度和模板缓冲区(如果您正在使用它们)通常也可以提高应用程序的性能.

在其他平台上,如果您要绘制每个像素,我总是发现它是一种清除颜色缓冲区的优化.(如果你要覆盖那种清晰的颜色,为什么要浪费时间填充颜色缓冲区?)

如何调用glClear()来提高性能?

iphone opengl-es

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

设置Thread.CurrentPrincipal异步?

在身份验证期间使用ASP.NET WebAPI进行Thread.CurrentPrincipal设置,以便控制器稍后可以使用该ApiController.User属性.

如果该身份验证步骤变为异步(以咨询另一个系统),CurrentPrincipal则会丢失任何变异(当调用者await恢复同步上下文时).

这是一个非常简化的示例(在实际代码中,身份验证发生在动作过滤器中):

using System.Diagnostics;
using System.Security.Principal;
using System.Threading;
using System.Threading.Tasks;

public class ExampleAsyncController : System.Web.Http.ApiController
{
    public async Task GetAsync()
    {
        await AuthenticateAsync();

        // The await above saved/restored the current synchronization
        // context, thus undoing the assignment in AuthenticateAsync(). 
        Debug.Assert(User is GenericPrincipal);
    }

    private static async Task AuthenticateAsync()
    {
        // Save the current HttpContext because it's null after await.
        var currentHttpContext = System.Web.HttpContext.Current;

        // Asynchronously determine identity.
        await Task.Delay(1000);
        var …
Run Code Online (Sandbox Code Playgroud)

c# async-await asp.net-web-api

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

itertools.tee等效于Boost :: Range?

Python itertools具有teen-plicating iterables:

def tee(iterable, n=2):
    it = iter(iterable)
    deques = [collections.deque() for i in range(n)]
    def gen(mydeque):
        while True:
            if not mydeque:             # when the local deque is empty
                newval = next(it)       # fetch a new value and
                for d in deques:        # load it to all the deques
                    d.append(newval)
            yield mydeque.popleft()
    return tuple(gen(d) for d in deques)
Run Code Online (Sandbox Code Playgroud)

我找不到相应的东西Boost::Range.我错过了什么或者我应该自己滚动吗?

c++ boost boost-range

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

哪个/什么是Error.ArgumentNull()?

有时我在代码示例中看到这个:

throw Error.ArgumentNull("someParameter");
Run Code Online (Sandbox Code Playgroud)

这里有一个例子在这里,上线89.

我想Error在我自己的代码中使用.我在哪里可以找到它?

(我试图自己找到它,我尝试using了该文件顶部的命名空间,我试图让Visual Studio找到它,到目前为止没有运气.)

.net c#

8
推荐指数
2
解决办法
1595
查看次数

os.error有什么意义?

为什么Python的os模块包含error,别名为OSError

是否有理由拼写它os.errorOSError当然,似乎与所有其他内置异常更加一致.

我希望os.py会有所启发,但error有时会使用OSError其他的.

为其中一个例外创建额外的名称似乎很愚蠢,但它仍然存在于Python 3.0中.我错过了什么?

python

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

Json.Net序列化对象丢失其Id值

我正在使用Json.Net来序列化和反序列化一个对象.

我遇到一个问题,其中反序列化对象recordPosted的Id为零.

序列化记录将包含Id为180

JsonSerializerSettings jsSettings = new JsonSerializerSettings();
jsSettings.ReferenceLoopHandling = ReferenceLoopHandling.Ignore;

var recordAsJson = JsonConvert.SerializeObject(recordToUpdate, 
                                Formatting.None, jsSettings);
//recordAsJson = {"Id":180,....


 var recordPosted = JsonConvert.DeserializeObject<record>(recordAsJson);
 //recordPosted = Id : 0
Run Code Online (Sandbox Code Playgroud)

我该如何解决这个问题?

编辑

public virtual int Id { get; private set; }
Run Code Online (Sandbox Code Playgroud)

c# json json.net

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

查找最初使用Visual Studio C#debugger抛出rethrown异常的位置?

重新抛出异常时的通常建议是使用throw;语句,以便保留原始堆栈跟踪.(例子)

但是,当我尝试这个简单的示例时,Visual Studio调试器不显示原始堆栈跟踪.

namespace ExceptionTest
{
    class Program
    {
        static void ThrowException()
        {
            throw new System.Exception();  // The line that I WANT the debugger to show.
        }

        static void Main(string[] args)
        {
            try
            {
                ThrowException();
            }
            catch (System.Exception)
            {
                System.Console.WriteLine("An exception was thrown.");

                throw;  // The line that the debugger ACTUALLY shows.
            }
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

如何使用调试器查找异常的原始来源?

c# debugging exception-handling visual-studio

7
推荐指数
2
解决办法
4661
查看次数

更多Pythonic转换为二进制?

这是一个人为的例子,说明我们的很多类如何返回自己的二进制表示(由C++读取).

def to_binary(self):
    'Return the binary representation as a string.'
    data = []

    # Binary version number.
    data.append(struct.pack('<I', [2]))

    # Image size.
    data.append(struct.pack('<II', *self.image.size))

    # Attribute count.
    data.append(struct.pack('<I', len(self.attributes)))

    # Attributes.
    for attribute in self.attributes:

        # Id.
        data.append(struct.pack('<I', attribute.id))

        # Type.
        data.append(struct.pack('<H', attribute.type))

        # Extra Type.        
        if attribute.type == 0:
            data.append(struct.pack('<I', attribute.typeEx))

    return ''.join(data)
Run Code Online (Sandbox Code Playgroud)

我不喜欢的事:

  • 每一行都以data.append(struct.pack(该行的独特部分分散注意力.
  • 字节顺序('<')一遍又一遍地重复.
  • 你必须记得返回样板''.join(data).

我喜欢什么:

  • 格式说明符出现在属性名称附近.例如,很容易看出它self.image.size是作为两个无符号整数写出来的.
  • 这些线(大多数)是独立的.例如,要从"属性"中删除Id字段,您不必触摸多行代码.

是否有更可读/ pythonic的方式来做到这一点?

python

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

在Python中,如何使用C++函数通过**参数返回已分配的结构数组?

我想在Python工具中使用一些现有的C++代码NvTriStrip.

SWIG通过简单的参数轻松处理功能,但主要功能GenerateStrips要复杂得多.

我需要在SWIG接口文件中放置什么来表明它primGroups实际上是一个输出参数,并且必须清除它delete[]

///////////////////////////////////////////////////////////////////////////
// GenerateStrips()
//
// in_indices: input index list, the indices you would use to render
// in_numIndices: number of entries in in_indices
// primGroups: array of optimized/stripified PrimitiveGroups
// numGroups: number of groups returned
//
// Be sure to call delete[] on the returned primGroups to avoid leaking mem
//
bool GenerateStrips( const unsigned short* in_indices,
                     const unsigned int    in_numIndices,
                     PrimitiveGroup**      primGroups,
                     unsigned short*       numGroups,
                     bool                  validateEnabled = …
Run Code Online (Sandbox Code Playgroud)

python swig

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

Mercurial:在包中包含秘密变更集?

使用Mercurial,我如何捆绑所有未知的更改集,包括秘密更改集?

我知道bundle--base选项恰好包括秘密的变更,但我不希望--base行为.(而且秘密变更集总是包含--base但似乎非常奇怪,但是如果没有秘密变更集,它就不会包含在内.不应该有单独的选项吗?)

仅供参考,我通常希望在尝试潜在危险的历史记录重写之前备份仅在我的本地仓库中的所有变更集.

mercurial bundle dvcs mercurial-phases

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