小编Chr*_*ris的帖子

如何在不使用额外内存的情况下连接列表?

如何在不增加内存的情况下连接大型列表?

请考虑以下代码段:

 Console.WriteLine($"Initial memory size: {Process.GetCurrentProcess().WorkingSet64 /1024 /1024} MB");
 int[] a = Enumerable.Range(0, 1000 * 1024 * 1024 / 4).ToArray();
 int[] b = Enumerable.Range(0, 1000 * 1024 * 1024 / 4).ToArray();
 Console.WriteLine($"Memory size after lists initialization: {Process.GetCurrentProcess().WorkingSet64 / 1024 / 1024} MB");
 List<int> concat = new List<int>();
 concat.AddRange(a.Skip(500 * 1024 * 1024 / 4));
 concat.AddRange(b.Skip(500 * 1024 * 1024 / 4));
 Console.WriteLine($"Memory size after lists concatenation: {Process.GetCurrentProcess().WorkingSet64 / 1024 / 1024} MB");
Run Code Online (Sandbox Code Playgroud)

输出是:

Initial memory size: 12 MB
Memory size …
Run Code Online (Sandbox Code Playgroud)

c#

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

获取函数的源文件行号

有没有办法对任何随机函数实现这一点?

class Class:
    def function(self):
        pass

import inspect
print(inspect.getlineno(Class.function))
Run Code Online (Sandbox Code Playgroud)

这只是给出:

File "C:\Users\user\AppData\Local\Programs\Python\Python37-32\lib\inspect.py", line 1479, in getlineno
    return frame.f_lineno
AttributeError: 'function' object has no attribute 'f_lineno'
Run Code Online (Sandbox Code Playgroud)

python reflection inspect

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

标签 统计

c# ×1

inspect ×1

python ×1

reflection ×1