Search Results

Search found 39 results on 2 pages for 'romkyns'.

Page 2/2 | < Previous Page | 1 2 

  • How do I rename a table in SQL Server Compact Edition?

    - by romkyns
    I've designed my SQL CE tables using the built-in designer in VS2008. I chose the wrong names for a couple. I am now completely stuck trying to find a way to rename them. I am refusing to believe that such a feature could have been "forgotten". How do I rename an existing table using the VS2008 designer, or a free stand-alone app?

    Read the article

  • How to determine whether a .NET exception is being handled?

    - by romkyns
    We're investigating a coding pattern in C# in which we'd like to use a "using" clause with a special class, whose Dispose() method does different things depending on whether the "using" body was exited normally or with an exception. To the best of my understanding, the CLR keeps track of the current exception being handled until it's been consumed by a "catch" handler. However it's not entirely clear whether this information is exposed in any way for the code to access. Do you know whether it is, and if so, how to access it? For example: using (var x = new MyObject()) { x.DoSomething(); x.DoMoreThings(); } class MyObject : IDisposable { public void Dispose() { if (ExceptionIsBeingHandled) Rollback(); else Commit(); } } This looks almost like System.Transactions.TransactionScope, except that success/failure is not determined by a call to x.Complete(), but rather based on whether the using body was exited normally.

    Read the article

  • How to draw Wingdings 2 characters outside of the 0..255 range in .NET?

    - by romkyns
    The standard windows Charmap utility shows quite a few characters in the "Wingdings 2" font whose character codes are greater than 255 - for example, 0xE4E shows a hand. However, if I try to draw these characters as follows: g.DrawString(new string((char) 0xE4E, 1), new Font("Wingdings 2", 20), brush, x, y); then all I get is a standard "box" replacement character. This is weird, because the above code works for Wingdings 2 symbols between 0x21 and 0xFF, and also works for ALL symbols in, say, Arial Unicode MS. How can I draw those characters from this particular font? Is there a separate API? (Win7; .NET 3.5 SP1) P.S. Here's the weird Character Map font with the duplicated character ranges:

    Read the article

  • Are finalizers ever allowed to call other managed classes' methods?

    - by romkyns
    I used to be pretty sure the answer is "no", as explained in Overriding the Finalize method and Object.Finalize documentation. However, while randomly browsing through FileStream in Reflector, I found that it can actually call just such a method from a finalizer: private SafeFileHandle _handle; ~FileStream() { if (this._handle != null) { this.Dispose(false); } } protected override void Dispose(bool disposing) { try { ... } finally { if ((this._handle != null) && !this._handle.IsClosed) // <=== HERE { this._handle.Dispose(); // <=== AND HERE } [...] } } I started wondering whether this will always work due to the exact way in which it's written, and hence whether the "do not touch managed classes from finalizers" is just a guideline that can be broken given a good reason and the necessary knowledge to do it right. I dug a bit deeper and found out that the worst that can happen when the "rule" is broken is that the managed object being accessed had already been finalized, or may be getting finalized in parallel on a separate thread. So if the SafeFileHandle's finalizer didn't do anything that would cause a subsequent call to Dispose fail then the above should be fine... right? Question: so there might after all be situations in which a method on another managed class may be called reliably from a finalizer? I've always believed this to be false, but this code suggests that it's possible and that there can be good enough reasons to do it. Bonus: Observe that the SafeFileHandle will not even know it's being called from a finalizer, since this is just a normal call to Dispose(). The base class, SafeHandle, actually has two private methods, InternalDispose and InternalFinalize, and in this case InternalDispose will be called. Isn't this a problem? Why not?...

    Read the article

  • Do I need multiple template specializations if I want to specialize for several kinds of strings?

    - by romkyns
    For example: template<typename T> void write(T value) { mystream << value; } template<> void write<const char*>(const char* value) { write_escaped(mystream, value); } template<> void write<char*>(char* value) { write_escaped(mystream, value); } template<> void write<std::string>(std::string value) { write_escaped(mystream.c_str(), value); } This looks like I'm doing it wrong, especially the two variants for const and non-const char*. However I checked that if I only specialize for const char * then passing a char * variable will invoke the non-specialized version, when called like this in VC++10: char something[25]; strcpy(something, "blah"); write(something); What would be the proper way of doing this?

    Read the article

  • How to Regex.IsMatch at a specified offset in .NET?

    - by romkyns
    Suppose I want to match "abc" within the string s only if it occurs exactly at index n. int n = 2; Console.WriteLine(new Regex("abc").IsMatch("01abc", n)); // true Console.WriteLine(new Regex("abc").IsMatch("0123abc", n)); // true (but want false) Console.WriteLine(new Regex("^abc").IsMatch("01abc", n)); // false (but want true) Seems that the only way to achieve this without using Substring on the input is something like this: var match = new Regex("abc").Match("0123abc", n); Console.WriteLine(match.Success && match.Index == n); This isn't too bad, except that when there is no match at the starting offset then the entire input will be scanned unnecessarily, which is probably slower for most regexes than actually creating a substring prior to the match. (I didn't time it though). Am I missing an obvious overload or setting that would restrict a match to the supplied offset only?

    Read the article

  • In Lua, how to pass vararg to another function while also taking a peek at them?

    - by romkyns
    It seems that in Lua, I can either pass vararg on to another function, or take a peek at them through arg, but not both. Here's an example: function a(marker, ...) print(marker) print(#arg, arg[1],arg[2]) end function b(marker, ...) print(marker) destination("--2--", ...) end function c(marker, ...) print(marker) print(#arg, arg[1],arg[2]) destination("--3--", ...) end function destination(marker, ...) print(marker) print(#arg, arg[1],arg[2]) end Observe that a only looks at the varargs, b only passes them on, while c does both. Here are the results: >> a("--1--", "abc", "def") --1-- 2 abc def >> b("--1--", "abc", "def") --1-- --2-- 2 abc def >> c("--1--", "abc", "def") --1-- test.lua:13: attempt to get length of local 'arg' (a nil value) stack traceback: ...test.lua:13: in function 'c' ...test.lua:22: in main chunk [C]: ? What am I doing wrong? Am I not supposed to combine the two? Why not?

    Read the article

  • Highly efficient filesystem APIs for certain kinds of operations

    - by romkyns
    I occasionally find myself needing certain filesystem APIs which could be implemented very efficiently if supported by the filesystem, but I've never heard of them. For example: Truncate file from the beginning, on an allocation unit boundary Split file into two on an allocation unit boundary Insert or remove a chunk from the middle of the file, again, on an allocation unit boundary The only way that I know of to do things like these is to rewrite the data into a new file. This has the benefit that the allocation unit is no longer relevant, but is extremely slow in comparison to some low-level filesystem magic. I understand that the alignment requirements mean that the methods aren't always applicable, but I think they can still be useful. For example, a file archiver may be able to trim down the archive very efficiently after the user deletes a file from the archive, even if that leaves a small amount of garbage either side for alignment reasons. Is it really the case that such APIs don't exist, or am I simply not aware of them? I am mostly interested in NTFS, but hearing about other filesystems will be interesting too.

    Read the article

  • How to call operator<< on "this" in a descendant of std::stringstream?

    - by romkyns
    class mystream : public std::stringstream { public: void write_something() { this << "something"; } }; This results in the following two compile errors on VC++10: error C2297: '<<' : illegal, right operand has type 'const char [10]' error C2296: '<<' : illegal, left operand has type 'mystream *const ' Judging from the second one, this is because what this points at can't be changed, but the << operator does (or at least is declared as if it does). Correct? Is there some other way I can still use the << and >> operators on this?

    Read the article

  • In Lua, can I easily select the Nth result without custom functions?

    - by romkyns
    Suppose I am inserting a string into a table as follows: table.insert(tbl, mystring) and that mystring is generated by replacing all occurrences of "a" with "b" in input: mystring = string.gsub(input, "a", "b") The obvious way to combine the two into one statement doesn't work, because gsub returns two results: table.insert(tbl, string.gsub(input, "a", "b")) -- error! -- (second result of gsub is passed into table.insert) which, I suppose, is the price paid for supporting multiple return values. The question is, is there a standard, built-in way to select just the first return value? When I found select I thought that was exactly what it did, but alas, it actually selects all results from N onwards, and so doesn't help in this scenario. Now I know I can define my own select as follows: function select1(n, ...) return arg[n] end table.insert(tbl, select1(1, string.gsub(input, "a", "b"))) but this doesn't look right, since I'd expect a built-in way of doing this. So, am I missing some built-in construct? If not, do Lua developers tend to use a separate variable to extract the correct argument or write their own select1 functions?

    Read the article

  • How to get number of entries in a Lua table?

    - by romkyns
    Sounds like a "let me google it for you" question, but somehow I can't find an answer. The Lua # operator only counts entries with integer keys, and so does table.getn: tbl = {} tbl["test"] = 47 tbl[1] = 48 print(#tbl, table.getn(tbl)) -- prints "1 1" count = 0 for _ in pairs(tbl) do count = count + 1 end print count -- prints "2" How do I get the number of all entries?

    Read the article

  • How do you protect yourself from runaway memory consumption bringing down the PC?

    - by romkyns
    Every now and again I find myself doing something moderately dumb that results in my program allocating all the memory it can get and then some. This kind of thing used to cause the program to die fairly quickly with an "out of memory" error, but these days Windows will go out of its way to give this non-existent memory to the application, and in fact is apparently prepared to commit suicide doing so. Not literally of course, but it will starve itself of usable physical RAM so badly that even running the task manager will require half an hour of swapping (after all the runaway application is still allocating more and more memory all the time). This doesn't happen too often, but when it does it's disastrous. I usually have to reset my machine, causing data loss from time to time and generally a lot of inconvenience. Do you have any practical advice on making the consequences of such a mistake less dire? Perhaps some registry tweak to limit the max amount of virtual memory an app is allowed to allocate? Or some CLR flag that will limit this only for the current application? (It's usually in .NET that I do this to myself.) ("Don't run out of RAM" and "Buy more RAM" are no use - the former I have no control over, and the latter I've already done.)

    Read the article

< Previous Page | 1 2