|
dan neely wrote: you've spread your weirdness all over the app instead of having it all contained in a single location at input time.
I do agree that I would not take such an extreme measure, unless performance is paramount. Coding for performance only is rarely pretty. In the context of the question -- how can you optimize x >> 8 -- I'm hard-pressed to come up with something significantly faster than avoiding the manipulation altogether. If you absolutely need it, it wouldn't be pretty.
|
|
|
|
|
Robert.C.Cartaino wrote: about a 5-10% improvement
On mine it took more than twice four times as long.
modified on Saturday, August 2, 2008 6:03 PM
|
|
|
|
|
|
If performance is the first priority, use unsafe code to access the array using a byte pointer. Something like:
fixed (byte* p = &theArray) {
for (int i = 0; i < theArray.Length; i++) {
p++;
byte lo = *(p++);
byte mid = *(p++);
byte hi = *(p++);
}
}
Despite everything, the person most likely to be fooling you next is yourself.
|
|
|
|
|
I was thinking of something similar; effectively using the byte preceding the array as the first byte, easy enough in C, but I don't think it would work in .net.
If he's reading bytes from a socket or similar, it's not a big deal.
|
|
|
|
|
PIEBALDconsult wrote: using the byte preceding the array as the first byte
You mean to effectively shifting the int value by eight bits?
There might be performance problems with accessing an int on an odd adress, so it would probably be faster to just shift the value, and it certainly is simpler.
Despite everything, the person most likely to be fooling you next is yourself.
|
|
|
|
|
Guffa wrote: shifting the int value
Shifting the entire array at once, but without actually moving it.
Guffa wrote: and it certainly is simpler
Yeah, I'd just stick with the right shift and be done with it.
It comes down to: "If performance is important, don't use .net."
Edit: I was thinking backward; I meant skip the first byte. I've now tried it in C, I just need to decide how I want to handle the last int.
modified on Saturday, August 2, 2008 1:23 PM
|
|
|
|
|
I made a few performance tests, and it looks like my suspicion about accessing ints on an odd address was correct.
It takes slightly longer (about 3%) to access the value using an adjusted pointer compared to just getting the value from the array and shifting it.
Despite everything, the person most likely to be fooling you next is yourself.
|
|
|
|
|
Here's what I just worked up in C, I still have compared it with shifting each int:
int masks[] = { 0xFFFFFFFF , 0x00FFFFFF , 0x0000FFFF , 0x000000FF } ;
int
ShiftAndSumArray
(
int* Array
,
unsigned Length
,
unsigned Shift
)
{
int result = 0 ;
int* a = (int*) ( ((char*) Array) + ( Shift %= sizeof(int) ) ) ;
unsigned i ;
for ( i = 0 ; i < Length-1 ; i++ )
{
result += a [ i ] ;
}
result += a [ i ] & masks [ Shift ] ;
return ( result ) ;
}
int a[] = { 0x00000100 , 0x00000100 , 0x00000100 , 0x00000100 } ;
printf ( "%d\n" , ShiftAndSumArray ( a , 4 , 1 ) ) ;
It may be possible in C#, but I haven't tried it.
|
|
|
|
|
Ha ha ha! Here it is in C#
private static readonly int[] masks = unchecked ( new int[] { (int) 0xFFFFFFFF , 0x00FFFFFF , 0x0000FFFF , 0x000000FF } ) ;
public static unsafe int
ShiftAndSumArray
(
int[] Array
,
uint Shift
)
{
int result = 0 ;
fixed ( int* b = Array )
{
int* a = (int*) ( ((byte*) b) + ( Shift %= sizeof(int) ) ) ;
int i ;
for ( i = 0 ; i < Array.Length-1 ; i++ )
{
result += a [ i ] ;
}
result += a [ i ] & masks [ Shift ] ;
}
return ( result ) ;
}
This appears to take about half the time of shifting each int separately, but it doesn't involve very much time either way;
100,000,000 (10,000 passes across an array of 10,000 ints) this way takes 507 milliseconds, the shifting technique takes 969 milliseconds.
(And 2665 milliseconds for the division technique.)
public static int
ShiftAndSumArray2
(
int[] Array
,
uint Shift
)
{
int result = 0 ;
int shift = (int) Shift % sizeof(int) * 8 ;
for ( int i = 0 ; i < Array.Length ; i++ )
{
result += Array [ i ] >> shift ;
}
return ( result ) ;
}
Correction: Earlier I had forgotten to Reset the Stopwatch , corrected results
457 milliseconds for altered pointer
459 milliseconds for shifted values
1768 milliseconds for division
I have also quickened up the implementations somewhat.
|
|
|
|
|
Hi all,
I have localizable form having some buttons and datagridview.
I added all the columns at design time to the datagridview.
Then I translated the localized version, say in German.
When I change the my culture info at run time, all buttons show the localized (translated)
texts, but my gridview does't show the translated column headers.
Any idea?
Thanks,
Muharrem
|
|
|
|
|
i don´t know how to set the columns headers name in c#, because i do it in sql.
But i bet it´s easy.
Now, are the data (to the datagridview) comming from sql database?
if right, write then there not in c#.
|
|
|
|
|
Let me more specific.
I added datagridview control to my form.
Then I edited columns through the property window in vs2005. So I added some column with names and columns header. I also defined the DataPropertyName of the column to the column which is in my
result table coming from a database table.So far so good.But I am also having the form in a different
language created with Localizable property of the form. In this second form I changed the column headers in design mode. What I expect is to see the localized column header when I change the form to
the localized version. All my other controls display their respective localized text but not gridview.
Any idea?
Thanks again
Muharrem
|
|
|
|
|
Hi all, I have a service that is supposed to show a form when starting, however it doesn't...
protected override void OnStart(string[] args)
{
runCapture();
base.OnStart(args);
}
System.IO.StreamWriter file;
public void runCapture()
{
try
{
requestCapture reqCap = new requestCapture();
reqCap.Show();
}
catch (Exception ex)
{
file = new StreamWriter(new FileStream("C:\\xampp\\htdocs\\captures\\Error_Log.log", System.IO.FileMode.Append));
this.file.WriteLine(ex.ToString());
this.file.Flush();
}
}
The thing is, it never errors either...
|
|
|
|
|
There are security issues with allowing services UI permissions like displaying forms. However, if this does not concern you and you have not done so already, you may be able to view the form via the service if you ensure you are using a local system account to start your service, and check the 'Allow Service to interact with desktop' check box in the log on properties of the service.
I think a better idea would be to have the UI separate from the service, and have the service communicate with the UI via a named pipe or...whatever...
|
|
|
|
|
|
|
Do you want to get data from a database and display in your application datagridview?
// this is a routine i wrote
public static void SP_WITH_DATAGRIDVIEW(string SP, DataGridView DATAGRIDVIEW_X, string PARAMETER_NAME1, SqlDbType SQLDBTYPE1, object OBJECT1, string PARAMETER_NAME2, SqlDbType SQLDBTYPE2, object OBJECT2)
{
SqlConnection conn = new SqlConnection(your_connection_string);
SqlCommand cmd = new SqlCommand();
cmd.Connection = conn;
cmd.CommandText = SP;
cmd.CommandType = CommandType.StoredProcedure;
// how many parameters to you have? here is 2, and of what kind?
cmd.Parameters.Add(PARAMETER_NAME1, SQLDBTYPE1).Value = OBJECT1;
cmd.Parameters.Add(PARAMETER_NAME2, SQLDBTYPE2).Value = OBJECT2;
conn.Open();
SqlDataAdapter sql_da = new SqlDataAdapter();
sql_da.SelectCommand = cmd;
DataTable dt = new DataTable();
sql_da.Fill(dt);
conn.Close();
DATAGRIDVIEW_X.DataSource = dt;
}
Good luck!!!
|
|
|
|
|
Hi,
I create this template but I have some problems compiling it
public class CuponsFormas<t> : CollectionBase
{
#region Add/Remove Methods
public int Add(T item)
{
return List.Add(item);
}
public void Remove(T item)
{
List.Remove(item);
}
#endregion
#region Load/Save Methods
public void LoadItens(XmlElement el)
{
XmlElement elAliqs = XmlConfigLoader.GetElement(el, "Aliquotas");
if (elAliqs != null)
{
XmlNodeList lista = elAliqs.GetElementsByTagName("Aliquota");
foreach (XmlNode node in lista)
{
Add((T)XmlConfigLoader.createXmlItem(
typeof(T), node as XmlElement));
}
}
}
public void SaveItens(XmlElement el)
{
if (List.Count > 0)
{
XmlElement items = el.OwnerDocument.CreateElement("Aliquotas");
foreach (T item in List)
XmlConfigLoader.createXmlEl(item, items);
el.AppendChild(items);
}
}
#endregion
}
</t>
createXmlItem return a IXmlItem derivated class (I made them up)
createXmlEl requires a IXmlItem derivated class
So, the compiler says cannot convert IXmlItem to T and connot convert T to IXmlItem
My question is: Is there any way to tell the compiler I'm sure T is a IXmlItem derivated?
Thanks,
Dirso.
|
|
|
|
|
public class CuponsFormas<T> : CollectionBase where T : IXmlItem
|
|
|
|
|
Hi All,
I have written a class that creates a dynamic SSIS package using C#, all is fine and dandy with this, it correctly creates and executes the package and the data plops into the SQL database as expected.
The problem is that I now need to 'tag on' another static package to be executed at the end of this dynamic package. If you were writing the SSIS package you would do this with an 'Execute Package Task' in the BIDS UI but I need to do this in a web service using C# code.
I can't actually find anything on Google or Code Project that deals with this scenario, any links or ideas would be great.
Thanks,
|
|
|
|
|
Just thought I'd answer this since I've fingured it out now.
I ended up adding a ExecuteProcess task instead.
1. Add a reference to Microsoft.SqlServer.ExecProcTask
2. Add in code:
MyTask2 = package.Executables.Add("STOCK:ExecuteProcessTask");
TaskHost th = MyTask2 as TaskHost;
th.Properties["Description"].SetValue(th, "<PackageName>");
th.Properties["Executable"].SetValue(th,"DTEXEC.exe");
th.Properties["Arguments"].SetValue(th, "<Your Arguments>");
PrecedenceConstraint pcFileTasks = package.PrecedenceConstraints.Add((Executable)MyTask1, (Executable)MyTask2);
pcFileTasks.Value = DTSExecResult.Success;
|
|
|
|
|
Hi all..
I have created a dll in c# for crawling the documents from sharepoint and to get the modified date,created Date..etc..
When i run it from server where sharepoint is installed its getting the created date and modified Date....
But when i run it from client pc...It is giving Debug Error....
when i comment this code....which i used for getting created date and modified date...
the code is
using (SPSite RootSite = new SPSite(listPath))
{
Console.WriteLine("1Entered SPSIte path");
using (SPWeb SiteCollection = RootSite.OpenWeb())
{
string path = listPath;
SPFile file = SiteCollection.GetFile(path);
string TimeCreated = file.TimeCreated.ToLongDateString();
Console.WriteLine("1.1: Created Date is :" + TimeCreated);
}
}
when i comment this code it works fine....is there any problem in it...but the same code works fine in server pc...I am totally confused..please give some idea......I am totally new to sharepoint and c#
manju
Hi..
I am Mnaju.I have Completed my B.E Computers Science.Lokking for a job.I am interested in VC++
manju
|
|
|
|
|
I want to show the SQL code of an SP in my program. Can I call any sys.procedure to get the code from a SP-name?
_____________________________
...and justice for all
|
|
|
|
|
This should do the trick:
EXEC sp_helptext '<stored procedure>'
Regards,
Rob Philpott.
|
|
|
|