我正在开发一个新的Web应用程序,并着眼于使用OWIN.我无法从任何文档中解决的一件事是,将C#应用程序创建为控制台应用程序并从其exe文件开始运行,或者将项目创建为类库/ dll,以及使用OwinHost之间的区别是什么? .exe启动它.
运行Owinhost.exe来启动进程是否会让您在控制台应用程序中运行它?
我目前正在研究一个非常大的遗留应用程序,它处理从各种来源收集的大量字符串数据(IE,名称,标识符,与业务相关的公共代码等).仅此数据在应用程序中可能需要多达200兆的内存.
我的一位同事提到了一种减少内存占用的可能策略(因为很多单个字符串在数据集中是重复的),可能是将"重复"字符串"缓存"在字典中并在需要时重新使用它们.所以例如......
public class StringCacher()
{
public readonly Dictionary<string, string> _stringCache;
public StringCacher()
{
_stringCache = new Dictionary<string, string>();
}
public string AddOrReuse(string stringToCache)
{
if (_stringCache.ContainsKey(stringToCache)
_stringCache[stringToCache] = stringToCache;
return _stringCache[stringToCache];
}
}
Run Code Online (Sandbox Code Playgroud)
然后使用这个缓存......
public IEnumerable<string> IncomingData()
{
var stringCache = new StringCacher();
var dataList = new List<string>();
// Add the data, a fair amount of the strings will be the same.
dataList.Add(stringCache.AddOrReuse("AAAA"));
dataList.Add(stringCache.AddOrReuse("BBBB"));
dataList.Add(stringCache.AddOrReuse("AAAA"));
dataList.Add(stringCache.AddOrReuse("CCCC"));
dataList.Add(stringCache.AddOrReuse("AAAA"));
return dataList;
}
Run Code Online (Sandbox Code Playgroud)
由于字符串是不可变的,并且框架完成了许多内部工作以使它们以类似于值类型的方式工作,我一半认为这只会将每个字符串的副本创建到字典中并且只需将其加倍使用的内存而不是仅仅传递对字典中存储的字符串的引用(这是我的同事所假设的).
因此,考虑到这将在大量字符串数据上运行...
这是否会节省任何内存,假设30%的字符串值将被使用两次或更多次?
假设这甚至可以正常工作吗?
我正在按照预期让我的DU工作有问题.我已经定义了一个新的DU,它具有类型<'a>的结果或者从System.Exception派生的任何Exception
open System
// New exceptions.
type MyException(msg : string) = inherit Exception(msg)
type MyOtherException(msg : string) = inherit MyException(msg)
// DU to store result or an exception.
type TryResult<'a, 't> =
| Result of 'a
| Error of 't :> Exception
//This is fine.
let result = Result "Test"
// This works, doing it in 2 steps
let ex = new MyOtherException("Some Error")
let result2 = Error ex
// This doesn't work. Gives "Value Restriction" error.
let result3 = …Run Code Online (Sandbox Code Playgroud) 我有一个实例集合Option<T>,想要从 转换IEnumerable<Option<T>>为Option<IEnumerable<T>>
如果所有选项都有值,那么我想要一个Some<IEnumerable<T>>包含收集值的值,如果集合中的任何项目都是None,那么我想要一个None<IEnumerable<T>>
这似乎是一个相当常见的函数转换,但我不确定它是否存在于主流函数库中,或者它会被称为什么。看起来与 类似FlatMap,但不完全一样,因为我不想只过滤掉这些None值。
我可以自己实现它,但想知道它是否已经作为功能构造存在。不介意什么语言,C#、Scala、Haskell 等。